Jump to content

php quiz


desithugg

Recommended Posts

<?
$question['1'] = "What is my name?";
$answer['q1']['a'] = "Albert"; //option a
$answer['q1']['b'] = "Alex"; //option b
$answer['q1']['c'] = "Saad"; //option c
$answer['q1']['right'] = "a"; //the correct option a
$question['2'] = "How many fingers am holding up?";
$answer['q2']['a'] = "1"; //option a
$answer['q2']['b'] = "3"; //option b
$answer['q2']['c'] = "4"; //option c
$answer['q2']['right'] = "c";  //the correct option c
if($_GET['check'] == "yes")
{
$total = $_GET['total'];
$i = "1";
while($i <= $total)
{
$qt = "q".$i;
$st = "answer_".$qt."_".$i;
$entred = $_POST[$st];
$r_answer = $answer[$qt]['right'];
$r_answer = $answer[$qt][$r_answer];
if($r_answer == $entred) { echo $i." was right<br>"; } else { echo $i." was wrong<br>"; }
$i++;
}
}
else
{
echo"<form action='?action=quiz&check=yes' method='post'>";
echo"<input name='total' type='hidden' value='".count($question)."'>";
echo"<table class='top' width='400' align='center'>";
$i = "1";
while($i <= "25")
{
if($question[$i] != "")
{
$q = "q".$i;
echo"<tr><td class='top' colspan='2'><b><font align='left'>".$i.")</font> ".$question[$i]."</b></td></tr>
<tr><td class='top' width='5'><b>A. <input name='answer_".$q."_".$i."' type='radio' value='".$answer[$q]['a']."'></b></td><td class='top'>".$answer[$q]['a']."</td></tr>
<tr><td class='top' width='5'><b>B. <input name='answer_".$q."_".$i."' type='radio' value='".$answer[$q]['b']."'></b></td><td class='top'>".$answer[$q]['b']."</td></tr>
<tr><td class='top' width='5'><b>C. <input name='answer_".$q."_".$i."' type='radio' value='".$answer[$q]['c']."'></b></td><td class='top'>".$answer[$q]['c']."</td></tr>
";
} 
$i++;
}echo"<tr><td class='top' colspan='2'><input type='submit' value='Check'></td></tr></form></table>";
}
?>

Umm...I put that togather like half an hour ago everything works fine accept the check part it shows up blank, i read through it like 10 times and didn't spot any errors

Link to comment
https://forums.phpfreaks.com/topic/44576-php-quiz/
Share on other sites

oh wait found it

echo"<form action='?action=quiz&check=yes' method='post'>";
echo"<input type='hidden' name='total' value='".count($question)."'>";

and in the checking part

$total = $_GET['total'];

the form submit method is set to post and i was trying to receive it using $_GET

thanx though

Link to comment
https://forums.phpfreaks.com/topic/44576-php-quiz/#findComment-216534
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.