Solved

Multiple radio button questions to go into mysql

Posted on 2012-04-10
2
949 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 32
simplest php form 3 57
How to use md5 hashing 3 25
Site hacked - decoding the PHP? 15 55
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

932 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

12 Experts available now in Live!

Get 1:1 Help Now