hi
i made a code that displays result of an exam
the out put :
"You answered 5 questions correctly and 15 questions incorrectly."
how do i get the values of 5 questions correctly answered in to a text field so that i could submit it to dbase?
<?php if ($useraction != 'checkit') {
$answer = array();
$question = array();
$qnum = array();
$orgid = array();
$i = 0;
$query = "SELECT * from entrytest ORDER by RAND() LIMIT 20";
//$result = mysql_query($query,$db);
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$answer[$i] = $row[5];
$question[$i] = $row['1'];
$qnum[$i] = $i;
$orgid[$i] = $row['id'];
$ans1[$i] = $row[2];
$ans2[$i] = $row[3];
$ans3[$i] = $row[4];
$i++;
}
$user_answer = array();
$i = 0;
$j = 1;
print "<FORM ACTION='$PHP_SELF' METHOD='post'><BR>\n";
while ($j <= 20) {
print "Question #" . $j . ': ' . "<b>".$question[$i]."</b><BR>\n";
print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='a'>".$ans1[$i]."<BR>\n";
print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='b'>".$ans2[$i]."<BR>\n";
print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='c'>".$ans3[$i]."<P><P>\n";
$i++;
$j++;
}
//print "<INPUT TYPE='hidden' NAME='qkey' VALUE='$questionkey'>\n";
$ii=0;
while ($ii<=19) {
print "<input type='hidden' name='answer[$ii]' value='$answer[$ii]'>\n";
print "<input type='hidden' name='orgid[$ii]' value='$orgid[$ii]'>\n";
$ii++;
}
print "<INPUT TYPE='hidden' NAME='useraction' VALUE='checkit'>\n";
print "<INPUT TYPE='submit' NAME='submitted' VALUE='Check Answers'>\n";
print "</FORM><br>\n";
} else { // <!-- if submitted, check the answers on the form -->
$i=0;
$correct = 0;
$incorrect = 0;
foreach ($_POST['orgid'] as $k =>$v) {
$orgid[$k] = $v;
}
$k = 0;
$m = 0;
while ($k <= 19) {
if ($_POST['user_answer'][$k] == $answer[$k]) {
$correct++;
unset ($_POST['user_answer'][$k]);
unset ($orgid[$k]);
} else {
$incorrect++;
}
$k++;
}
echo "<br><br>";
//$correct = $_POST['correct'];
echo "You answered $correct questions correctly and $incorrect questions incorrectly.<br>";
?>
<form name="form1" method="post" action="Untitled-22.php">
<input name="textfield" type="text" value= "" >
<input type="submit" name="Submit" value="Submit">
</form>
<?
if($correct > 16)
{
echo "<br><br>Well done! You passed with flying colors. I hope you went outside today and got some fresh air and exercise.<br><br>";
}
elseif ($correct > 10)
{
echo "<br><br>You fell a bit short of a passing grade this time. We're sure you'll do better after you brush up
on your molecular biophysics.<br><br>";
}
else {
echo "<br><br>Well you made a mess of that. Try reading a book instead of skateboarding tomorrow.<br><br>";
}
}
?>