Ich habe mir ein PHP-Quiz für meine HP besorgt, aber die Auswertung funktioniert nicht. Hier der Code:
<?php
include("contentdb.php");
$display = mysql_query("SELECT * FROM $table ORDER BY id",$db);
if (!$submit) {
echo "<form method=post action=$PHP_SELF>";
echo "<table border=0>";
while ($row = mysql_fetch_array($display)) {
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
echo "<tr><td><table class="table5" border="1"><tr><td><div class="div2"><b>$question</b></div></td></tr></table><font style="font-size: 4pt"><br></font></td></tr>";
echo "<tr><td><input type=radio name=q$id value="$opt1"> $opt1<br><input type=radio name=q$id value="$opt2"> $opt2<br><input type=radio name=q$id value="$opt3"> $opt3<font style="font-size: 4pt"><br><br><br></font></td></tr>";
}
echo "</table>";
echo "<div align="center"><input type='submit' value='Auswertung' name='submit'></div>";
echo "</form>";
}
elseif ($submit)
{
$score = 0;
$total = mysql_num_rows($display);
while ($result = mysql_fetch_array($display))
{
$answer = $result["answer"];
$q = $result["q"];
if ($$q == $answer)
{
$score++;
}
}
echo "<p align=center><b>You scored $score out of $total</b></p>";
echo "<p>";
if ($score == $total) {
echo "Congratulations! You got every question right!";
}
elseif ($score/$total < 0.34) {
echo "Oh dear. Not the best score, but don't worry, it's only a quiz.";
}
elseif ($score/$total > 0.67) {
echo "Well done! You certainly know your stuff.";
}
else {
echo "Not bad - but there were a few that caught you out!";
}
echo "</p>";
echo "<p>Here are the answers:";
echo "<table border=0>";
$display = mysql_query("SELECT * FROM $table ORDER BY id",$db);
while ($row = mysql_fetch_array($display)) {
$question = $row["question"];
$answer = $row["answer"];
$q = $row["q"];
echo "<tr><td><br>$question</td></tr>";
if ($$q == $answer)
{
echo "<tr><td>»you answered ${$q}, which is correct</td></tr>";
}
elseif ($$q == "") {
echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>";
}
else {
echo "<tr><td>»you answered ${$q}. The answer is $answer</td></tr>";
}
}
echo "</table></p>";
}
?>
Wenn ich auf "Auswertung" klicke, wird stattdessen die index.php angezeigt und keine Auswertung erscheint. Die Seite wird über den Link index.php?site=quiz.php aufgerufen.