Solved

Multiple radio button questions to go into mysql

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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