I am trying to check if the answer that the user chose was correct, but it doesn't work properly:
<form method="post">
<?php
$question = mysql_query("SELECT * FROM `questions`");
$stat = mysql_fetch_assoc($question);
$num = mysql_num_rows($question);
$questionid = 0;
for($i=0;$i<=$num;$i++)
{
$question = mysql_query("SELECT * FROM `questions` WHERE `id`='$i'");
$stat = mysql_fetch_assoc($question);
//if($stat['answer'] == null
echo $stat['question'] . '<br />';
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer1']."<br />";
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer2'] . '<br />';
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer3'] . '<br />';
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer4'] . '<br />';
$questionid++;
$x = $x+1;
}
echo $result;
?>
<input type="submit" name="go" value="Go" />
</form>
That part basically:
$x = 1;
$question = mysql_query("SELECT * FROM `questions`");
$stat = mysql_fetch_assoc($question);
$num = mysql_num_rows($question);
if(isset($_POST['go']))
{
for($i=0;$i<$num;$i++)
{
if ($_POST['ans'.$x] == $row['correct'])
{
$result = $result + 1;
}
$x = $x + 1;
}
}
For some reason it doesn't post the results properly and I think something is wrong with the code, would appreciate help.