Solved

Multiple radio button questions to go into mysql

Posted on 2012-04-10
2
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
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 count occurrences of each item in an array.

733 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