I have a php page with multiple choice quiz questions like this
<p>1. Is Manhattan near New York?<br>
<input type="radio" name="ans1" value="3">
Yes<br>
<input type="radio" name="ans1" value="2">
Maybe<br>
<input type="radio" name="ans1" value="1">
No</p>
<p>2. Do you like Indian food?<br>
<input type="radio" name="ans2" value="1">
Some times<br>
<input type="radio" name="ans2" value="3">
Never<br>
<input type="radio" name="ans2" value="2">
Always</p>
The page posts to itself and checks if the answer is right or wrong like this
if($ans1 == "3") {
$test_complete .="Question one is <span class='green'>correct</span>, well done!<br/>";
}else{
$test_complete .="Question one is <span class='red'>incorrect</span>!<br/>";
}
// change the quest2 to the right answer
if($ans2 == "2") {
$test_complete .="Question two is <span class='green'>correct</span>, well done!<br/>";
}else{
$test_complete .="Question two is <span class='red'>incorrect</span>!<br/>";
}
Now instead of telling the user that answer one or two is correct i would like to run a counter where it calculates the number of correct and number of wrong answers and displays it in two table boxes along with one box for total number of questions.
There are multiple ways to do this. I would have an array of correct questions which corresponds the questions and then compare them. For example: