Hi Everyone,
Right off, I know this is messed since I keep getting stuck in a loop when I run this.
I have 3 files.
Form #1) Is a form asking you how many questions you want (on form #2) and the title of the quiz.
Form #2) Builds the form from the answers from form #1 then lets you submit the questions and answers for the quiz.
Form #3) SHOULD take the results and build list of inserts so I can insert them all into the database at once (this is where I get stuck in a loop.)
Form #1
$sql = "SELECT * FROM " . $table;
$query = $DB->Query($sql);
$num = mysql_num_rows($query);
echo 'The number of quizzes currently is : ' . $num . '<br><br>';
$new_quizID = $num +1;
?>
<form action="setup2a.php" method="POST" target="_self">
<p class="font"><span class="boldFont">How many questions do you want on the quiz?</span>
<input name="num_questions" type="text" size="3" maxlength="3" /></p>
<p class="font"><span class="boldFont">What is the title of the quiz?(Maximum 200 letters!)</span>
<input name="Title" type="text" size="60" maxlength="200" /></p>
<p align="center">
<input name="ID" type="hidden" value="<?PHP echo $new_quizID; ?>">
<input type="submit" value="submit" />
</p>
</form>
Form #2
<form action="setup3a.php" method="POST" target="_self">
<table width="600" border="0" align="left" cellspacing="1">
<tr>
<td width="220" class="font">Your Name:</td>
<td width="280" class="font"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif"><strong>
<input name="name" value="<?php echo $_POST['name'];?>" type="text" size="40" />
</strong></font></td><td></td><td></td>
</tr>
<tr>
<td class="font">Your Teacher's Email:</td>
<td class="font"> <input name="email" value="<?php echo $_POST['email'];?>" type="text" size="40" /> </td><td></td><td></td>
</tr>
<tr><td></td><td></td><td width="50">True</td><td width="50">False</td></tr>
<?PHP
$counter = 1;
while ( $counter <= $num_questions ) {
echo "<tr>";
?>
<td width="220" class="font">Question #<?PHP echo $counter; ?></td>
<td width="280" class="font"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif"><strong>
<input name="Q<?PHP echo $counter; ?>" value="" type="text" size="40" />
</strong></font></td>
<td width="50"><input name="A<?PHP echo $counter; ?>" type="radio" value="1" /></td>
<td width="50"><input name="A<?PHP echo $counter; ?>" type="radio" value="0" /></td>
</tr>
<?PHP $counter = $counter + 1; ?>
<?PHP } ?>
<tr><td align="center" colspan="4"><br />
<input name="ID" type="hidden" value="<?PHP echo $ID; ?>">
<input name="Title" type="hidden" value="<?PHP echo $Title; ?>">
<input name="num_questions" type="hidden" value="<?PHP echo $num_questions; ?>">
<input type="submit" value="submit" />
</form>
Form #3
$_SESSION = $_POST;
$table = 'Form_ID';
$db = 'inthecla_Misc';
$Submit = $_POST['Submit'];
$QuizID = $_POST['ID'];
$Title = $_POST['Title'];
$Q[] = $_POST['Q[]'];
$A[] = $_POST['A[]'];
//include connection
include("../includes/mysql_class.php");
//make a new db connection
$DB = new mysql();
//connect
$connection = $DB->Connect($host, $name, $pass, $db);
for($i=0;$i<2;$i++)
{
$Q.$i = $_POST['Q.$i'];
$A.$i = $_POST['A.$i'];
$c=$c+1;
$result.$c = "|" . $Q[$i] . "|" . $A[$i] . "|<br>";
echo 'Result' .$i . ' = ' . $result . $c . '<br>';
}
$_SESSION = $_POST;
echo "<br><br><br>Here's the list of variables from the form!";
echo "<pre>";
var_dump($_SESSION);
echo "</pre>";
for($i=0;$i<2;$i++){
$sql ="insert into Questions";
$sql .="(QuizID, Title, Q.$i, A.$i)";
$sql .="values('$QuizID', '$Title', '$Questions', '$Answer')";
}
$result = mysql_query($sql);
if(!mysql_query($result)){
echo mysql_errno().'<br>'.mysql_error().'<br><br>';
} else {
echo 'It worked!';
}
I wrote this from several posts here on this forum and 'tried' to adapt it to what I am attempting to do.
Any ideas?
Thanks,
Don