Please help me in my coding.
Here is my code:
Code: Select all
<?
session_start();
$db = mysql_connect("localhost");
mysql_select_db("examination",$db);
if(!$_SESSION['bago'] && !$_SESSION['bago2']){
echo '<br><font size = "3" color = "#000000"><strong>Invalid session!
<br>You cannot view this page.</font></strong><br><br>';
exit;
}
?>
<html>
<body>
<FORM name ="form1" method ="post" action ="dummy.php">
<table width="800" border="0" align="center" class="underresult">
<?
$query = "SELECT *
FROM mathquestions";
$result = mysql_query($query);
for($i = 0; $i < mysql_num_rows($result); $i++){
$question_number ++;
$question = mysql_result($result, $i, "question");
$choiceA = mysql_result($result, $i, "choiceA");
$choiceB = mysql_result($result, $i, "choiceB");
$choiceC = mysql_result($result, $i, "choiceC");
$choiceD = mysql_result($result, $i, "choiceD");
$answer = mysql_result($result, $i, "answer");
$selected_radio = $_POST[$question_number];
if ($selected_radio == $answer) {
$score ++;
$valid = true;
if($valid){
$result2 = mysql_query("update examinee set math = '".$score."'
where firstname = '".$_SESSION['bago']."'");
}
}
echo '<tr>
<td></td>';
'</tr>';
echo '<tr>
<td> </td>';
'</tr>';
echo '<tr>
<td width = "20" align = "left" valign = "top"><font class = "questions">'.$question_number.'.</span><td>';
echo '<td width = "280" align = "left" valign = "top" ><font class = "questions">'.$question.'</span></td>';
echo '<td width = "125" align = "left" valign = "center" > </td>';
echo '<td width = "125" align = "left" valign = "center" > </td>';
echo '<td width = "125"align = "left" valign = "center" > </td>';
echo '<td width = "125" align = "left" valign = "center" > </td></tr>';
echo '<tr>
<td> </td>';
'</tr>';
echo '<tr>
<td width = "20" align = "left" valign = "top"><td>';
echo '<td width = "280" align = "left" valign = "center" > </td>';
echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceA.'" />'.$choiceA.'</span></td>';
echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceB.'" />'.$choiceB.'</span></td>';
echo '<td width = "125"align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceC.'" />'.$choiceC.'</span></td>';
echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceD.'" />'.$choiceD.'</span></td></tr>';
echo '<tr>
<td colspan = "7" class = "exam">
</td>
</tr>';
}
?>
</table>
<br /><br />
<table width="240" border="0" align="center" class="session">
<tr>
<td> <Input type = "Submit" Name = "Submit" VALUE = "Submit">
</tr>
</table>
<br />
</FORM>
</body>
</html>
Or when i press on the submit button the score will be added in the database and a message will appear showing a message("Thank you for taking the exam").
thanks in advance please help