Solved

Multiple radio button questions to go into mysql

Posted on 2012-04-10
2
948 Views
Last Modified: 2012-07-04
Hi experts

My question is probably very simple to resolve, however I have hit a brick wall.  I have a questionnaire form which has multiple questions, each with 4 different radio buttons as each answer.  I need to add the results, on submit, to mysql.  I think I've got the guts of it here but cannot get the loop right.

$qtquery = "SELECT * FROM FB_QUESTIONS ORDER BY qid";
$qtresult = mysql_query($qtquery) or die(mysql_error());
$qt_num = mysql_num_rows($qtresult);
		
if ($qtresult && $qt_num>0) {
while ($qtrow = mysql_fetch_array($qtresult)) {
                          <input name="<?php echo $qtrow[qid];?>[]" type="radio" value="<?php echo $qtrow[qA];?>" class="radiobutton"><?php echo $qtrow[qA];?>
			  <input name="<?php echo $qtrow[qid];?>[]" type="radio" value="<?php echo $qtrow[qB];?>" class="radiobutton"><?php echo $qtrow[qB];?>
			  <input name="<?php echo $qtrow[qid];?>[]" type="radio" value="<?php echo $qtrow[qC];?>" class="radiobutton"><?php echo $qtrow[qC];?>
			  <input name="<?php echo $qtrow[qid];?>[]" type="radio" value="<?php echo $qtrow[qD];?>" class="radiobutton"><?php echo $qtrow[qD];?>
}
}	

//insert sql

for ($i=1; $i<=50; $i++){
$qid = $_POST['qid'];
$answer= $_POST['answer'];
$userid= $_POST['userid'];
$insert="INSERT INTO FB_FEEDBACK (userid, qid, answer)VALUES ($userid, $qid, $answer)";
mysql_query($insert);
}

Open in new window

0
Comment
Question by:studio1090
2 Comments
 
LVL 11

Accepted Solution

by:
un1x86 earned 500 total points
ID: 37831261
Hi

Not sure if this is a problem or not. You might send some echo output of different variables. But what I see so far.

What is the output of

<?php echo $qtrow[qid];?>[]

You use $_POST['gid'] and same for answer and userid. But where in the form do you have this specified?

<?php echo $qtrow[qid];?>[] -> seems to get an ID from the Database. So the name of that radio button would be name="someID[]".

If you loop through IDs with for you might want to use $i as your ID maybe? so

$gid = $_POST[$i];

In order to help you here you need to send us the output of

echo "<pre>";
print_r($_POST);
echo "</pre>";

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37832051
Please post a link to the web page that demonstrates this in action.  I would like to see the generated HTML form.  Thanks, ~Ray
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now