Let's suppose you keep all the correct answers in an array. The array is indexed by the name of the input field.
Also, we'll suppose you keep the current high score in "highscore.dat".
<?php
$high_score_file = "highscore.dat";
$answers = array('name' => 'john', ...);
$score = 0;
$high_score = (int) file_get_contents($high_score_file);
echo "The current high score is {$high_score}.\n";
// Check each answer in the $answers array with the
// value submitted by the user.
foreach($answers as $input_field => $answer)
{
if (isset($_POST[$input_field]) &&
($_POST['input_field'] == $answer))
{
++$score;
}
}
// Print total score to user.
echo "Your score is {$score}.\n";
if ($score > $high_score)
{
echo "You set a new high score!\n";
// write new high score to file:
$fp = fopen($high_score_file, 'w');
if ($fp)
{
fwrite($fp, "{$score}");
}
}
?>
Take care,
Nik
http://www.bigaction.org/