?
Solved

Multiple radio button questions to go into mysql

Posted on 2012-04-10
2
Medium Priority
?
996 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:
Chris Sandrini earned 1500 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 111

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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