I'm having a problem. Actually I'm making a quiz in php. So my client will be having 4 options which are displayed in radio buttons. So I want to get the option he/she has selected in the variable $ answer so how to do that. My code is as follows:
<?php
$qid = $_POST['q_id'];
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('quiz', $con) or die(mysql_error());
$q = "select * from question where qno=$qid";
$rq = mysql_query($q,$con);
echo $rq;
if(!$rq)
{
echo " the sql query faiiled to work ";
}else
{
while ($sub_row=mysql_fetch_array($rq))
{
$id=$sub_row["qno"];
$question=$sub_row["question"];
$option1=$sub_row["option1"];
$option2=$sub_row["option2"];
$option3=$sub_row["option3"];
$option4=$sub_row["option4"];
echo "<h5>Q".$id." : ".$question."</br></h5>";
echo "</br></br>";
echo "<h4><input type= radio name=\"{$id}\" value=\"{$option1}\">$option1</h4></br>";
echo "<h4><input type= radio name=\"{$id}\" value=\"{$option2}\">$option2</h4></br>";
echo "<h4><input type= radio name=\"{$id}\" value=\"{$option3}\">$option3</h4></br>";
echo "<h4><input type= radio name=\"{$id}\" value=\"{$option4}\">$option4</h4></br></br>";
}
}
?>
You can add <input type='hidden' name='question' value='{$id}'>
And then it's easy - $answer = $_POST[$_POST['question']]