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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.