Forum Moderators: coopster
Can someone help? Thanks!
[edited by: coopster at 3:50 pm (utc) on Nov. 16, 2006]
[edit reason] removed code dump [/edit]
Can you please just give us just the 100th line in the code that is creating the error?
Excessive code dumps aren't favored at this forum because it makes it hard to read and it isn't necessary either. Read the Charter [webmasterworld.com] for more details on this. Also, refer to this thread [webmasterworld.com] regarding troubleshooting.
Thanks
Here's a simplified example of what you want to do. It seems that some of your logic isn't correct, as well as some of your syntax.
page.php
<?php
if(empty($_POST['answers'])) {
?>
<form action="index.php" method="post">
Type question 1 here:
<select name="answers[]">
<option value="0" selected>Choose an answer</option>
<option value="Answer one">Answer one</option>
<option value="Answer two">Answer two</option>
<option value="Answer three">Answer three</option>
</select><br/>
Type question 2 here:
<select name="answers[]">
<option value="0" selected>Choose an answer</option>
<option value="Answer one">Answer one</option>
<option value="Answer two">Answer two</option>
<option value="Answer three">Answer three</option>
</select>
<input type="submit" value="Grade!" />
</form>
<?php
exit();
}
//else, continue with the grading!
$correct_answers = array("Answer two","Answer three");
$their_answers = $_POST['answers'];
$num_questions = count($correct_answers);
$score = 0;
for($i = 0; $i < $num_questions; $i++) {
if($their_answers[$i] === $correct_answers[$i]) {
$score++;
echo 'Question '.($i+1).' correct!<br/>';
} else {
echo 'Question '.($i+1).' is incorrect :(<br/>';
}
}
echo 'You got '.($score/$num_questions*100).'% of the questions correct!';
?>
There we go. It seems nicer, now does it work? I didn't try it, but everything looks ok. Give it a go first, and then try to see how you can implement it into your site :)
I'll be happy to explain how it all works; just ask if you want an explanation.