I'm just playing around, trying to write a complete php quiz app without looking at other php code (the way i usually code, im still learning all the goodies) but i ran into a problem... is what im doing possible (im getting an error with it the way it is)
When the user enters in questions and answers below the form they can look at what they have asked on previous questions of the quiz.
here is the code, its not done obviously.
<?php
session_start();
$questnum = $_POST['questnum'];
$quiz = $_POST['quiz'];
$quizname = $_POST['quizname'];
echo <<<EOT
<head><title>Make a quiz</title></head>
<body bgcolor=white>
<form method="post" action="make.php">
EOT;
if ($quiz == "")
{
//get number of quizes and then add one
}
if ($quizname == "")
{
//Set the quiz name.
echo "Quiz Name: <input type = \"text\" name=\"quizname\"><br><br>";
}
else
{
//or show the name if its already been set.
echo "Quiz Name: $quizname<br>";
echo "<input type=\"hidden\" name=\"quizname\" value=\"$quizname\">";
}
if ($questnum == "")
{
//set the number of questions to 1
$questnum = 1;
echo "<input type=\"hidden\" name=\"questnum\" value=\"$questnum\">";
}
else
{
//add 1 if questions have been added.
$_SESSION['$questnum-1'] = $_POST['$questnum-1'];
$_SESSION['$questnum-2'] = $_POST['$questnum-2'];
$_SESSION['$questnum-3'] = $_POST['$questnum-3'];
$_SESSION['$questnum-4'] = $_POST['$questnum-4'];
$_SESSION['$questnum-5'] = $_POST['$questnum-5'];
$_SESSION['$questnum-6'] = $_POST['$questnum-6'];
$questnum = $questnum + 1;
echo "<input type=\"hidden\" name=\"questnum\" value=\"$questnum\">";
}
echo "<b>Question #$questnum</b><br>";
echo <<<EOT
Question: <input type="text" name="$questnum-1"><br>
Choice A: <INPUT TYPE="radio" NAME="$questnum-6" VALUE="a"><input type="text" name="$questnum-2"><br>
Choice B: <INPUT TYPE="radio" NAME="$questnum-6" VALUE="b"><input type="text" name="$questnum-3"><br>
Choice C: <INPUT TYPE="radio" NAME="$questnum-6" VALUE="c"><input type="text" name="$questnum-4"><br>
Choice D: <INPUT TYPE="radio" NAME="$questnum-6" VALUE="d"><input type="text" name="$questnum-5"><br>
<br><input type="submit" value="Next"><br><br><br>
<hr>
EOT;
//show the questions entered so far.
if ($questnum >= 2)
{
for ($i=1; $i <= $questnum; $i = $i + 1)
{
echo "<b>Question $1 - $_SESSION['$i-1']</b><br>";
echo "Choice A: $_SESSION['$i-2']<br>";
echo "Choice B: $_SESSION['$i-3']<br>";
echo "Choice C: $_SESSION['$i-4']<br>";
echo "Choice D: $_SESSION['$i-5']<br>";
echo "Answer: $_SESSION['$i-6']<br><br>";
}
}
?>
Get how im trying to do it? is that the "correct" way to do it? everything works up unti the part where im trying to show the questions that the user has entered this far. anyone have a solution? thanks in advance!