Hi rr,
OK, I made the question/answers one form, and it is working except I cannot seem to get the logic for the 'correct answer' radio button. Here is what I have so far.
<table>
<tr><td colspan="3" align="center"><?php echo $quiz_name; ?></td></tr>
<tr><td width="90">
<label>Question</label></td><td colspan="2">
<input name="question" type="text" size="100"/>
</td></tr>
<tr><td width="90">
<label>Answer 1</label></td><td>
<input name="answers[]" type="text" size="100"/>
</td><td><?php echo '<input type="radio" name="correct" value="1">'; ?></td></tr>
<tr><td width="90">
<label>Answer 2</label></td><td>
<input name="answers[]" type="text" size="100"/>
</td><td><?php echo '<input type="radio" name="correct" value="1">'; ?></td></tr>
<tr><td width="90">
<label>Answer 3</label></td><td>
<input name="answers[]" type="text" size="100"/>
</td><td><?php echo '<input type="radio" name="correct" value="1">'; ?></td></tr>
<tr><td width="90">
<label>Answer 4</label></td><td>
<input name="answers[]" type="text" size="100"/>
</td><td><?php echo '<input type="radio" name="correct" value="1">'; ?></td></tr>
</table>
Then on the process page, I save the question.
mysql_select_db($dbname, $conn) or die (mysql_error());
$sql ="insert into quiz_questions ";
$sql .="(quiz_id) ";
$sql .="values ('$quiz_id')";
if(!mysql_query($sql)){
echo mysql_errno().'(1)<br>'.mysql_error().'<br><br>';
}
Then insert the quiz_id to relate it to the question.
mysql_select_db($dbname, $conn) or die (mysql_error());
$query="SELECT question_id
FROM quiz_questions
WHERE quiz_id='".$quiz_id."'";
echo $query.'<br />';
$result = mysql_query($query) or die(mysql_error());
while($myrow=mysql_fetch_array($result)) {
$question_id = $myrow['question_id'];
}
Then get the question_id for that question.
mysql_select_db($dbname, $conn) or die (mysql_error());
$sql ="insert into questions ";
$sql .="(question_id, question) ";
$sql .="values ('$question_id', '$question')";
if(!mysql_query($sql)){
echo mysql_errno().'(2)<br>'.mysql_error().'<br><br>';
}
Now try to insert the answers...
$sql ="insert into answers ";
$sql .="(question_id, answer, correct) ";
$sql .="values ('$question_id', '$answers', '$correct')";
$result = mysql_query($sql) or die(mysql_error());
since there can only be 1 correct answer and for the other rows, there is no value for $correct, I get "Column count doesn't match value count at row 1".
Am I going down the correct path, or am I way off base with this method?
Thanks,
Don