ok heres the problem in plain english:
-i have a php file with a form using a textbox. what i type in the textbox
is the name of a quiz, which is then used in a seperate php file as a
variable to be used in an SQL query. This part works!
-but, the query will only be displayed once, and later on down the same
file-the exact same variable is no longer recognised.
the problem variable in quiz2.php is $storedquiz, which is supposed to
store the input taken from the textfield on quiz1.php
any help is appreciated!
John
QUIZ 1:
<form name = "quiznames" method="post" action="quiz2.php">
<p><br>
<center><b>Quiz name:</b><br>
<center><input type="Text" name="quizname" size="50">
<br><br>
<center><input type="Submit" name="take" value="Take Quiz">
</p>
</form>
QUIZ 2:
<?
$storedquiz = $quizname;
include("contentdb.php");
$display = mysql_query("SELECT * FROM $storedquiz ORDER BY id",$db); //stored quiz IS recognised
if (!$submit) {
echo "<form method=post action=$PHP_SELF>";
echo "<table border=1 padding=1 cellspacing=2 margin=3 width = 100% height = 70%>";
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 colspan=3 rowspan=1><br><b><align=left>$question</align><br></b><br></td></tr>";
echo "<tr align=right><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"><br></td></tr>";
}
echo "</table>";
echo "<br><center><input type='submit' value='See how you did' name='submit'></center>";
echo "</form>";
echo "<center><font color = #CCFFFF size = 15>TEST 1: $storedquiz</center>";
}
else
{
$display = mysql_query("SELECT * FROM $storedquiz ORDER BY id",$db); // $stored quiz not being recognised
$score = 0;
$total = mysql_num_rows($display);
while ($result = mysql_fetch_array($display))
{
$answer = $result["answer"];
$q = $result["q"];
if ($$q == $answer)
{
$score++;
}
}
echo "<br>";
echo "<br>";
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 "You need to do a lot of study, check the help pages for advice.";
}
elseif ($score/$total > 0.67) {
echo "Good score, but you need to study some more.";
}
else {
echo "Poor score, if you want to be a Scientist you have a lot to learn!";
}
echo "</p>";
echo "<p>Here are the answers:";
echo "<Center><table border=1 width = 100%>";
$storedquiz = $quizname;
include("contentdb.php");
$display = mysql_query("SELECT * FROM $storedquiz ORDER BY id",$db); // $stored quiz not being recognised
while ($row = mysql_fetch_array($display)) {
$question = $row["question"];
$answer = $row["answer"];
$q = $row["q"];
echo "<tr><td><br><b>$question</b></td></tr>";
if ($$q == $answer)
{
echo "<tr><td><i>»You answered ${$q}</i>,<br><br> which is correct</td></tr>";
}
elseif ($$q == "") {
echo "<tr><td><i>»You didn't select an answer</i>.<br><br> The answer is $answer</td></tr>";
}
else {
echo "<tr><td><i>»You answered ${$q}.</i><br><br> The answer is $answer</td></tr>";
}
}
echo "</table></p></center>";
}
?>