Hello everyone, I have a datatbase containing fields id, question, answer, and type. The questions are in true/false format, multiple choice and fill in the blank(text). At the moment, I am only trying to get the true and false questions to work. My code is as follows
<?php
$connection = mysql_connect("localhost","root","root") or die("couldn't connect");
$select = mysql_select_db("login") or die ("cannot select database!");
$query = mysql_query("SELECT * FROM questions");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
//code to login
while($row = mysql_fetch_assoc($query))
{
$dbquestion = $row['question'];
$dbanswer = $row['answer'];
$dbtype = $row['type'];
$dbid = $row['id'];
$correctanswer = explode('|',"$dbanswer");
switch($dbtype){
case "mchoice":
echo"<br/>"; echo $dbquestion; echo"<br/>";
break;
case "boolean":
echo"<br/>"; echo $dbquestion; echo"<br/>";
echo $correctanswer[0];
//display radio buttons
?>
<form name="boolean" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
True
<input name="question" type="radio" value= "True" />
False
<input name="question" type="radio" value= "False" />
<input name="id" input type="hidden" value="<?php $dbid ?>" />
<input type="submit" name="submit" id="submit" value="Submit" />
<?php
echo "The answer submitted was ";
echo $_POST['question'];
?>
<?php
break;
case "text":
echo"<br/>"; echo $dbquestion; echo"<br/>";
//display text box
break;
}
}
}
?>
The problem I'm having is that this creates a submit button for each question. When choosing true or false for the answer and pressing submit, the answer is selected for every question. I need the code to look at what the user has entered, check the answer against correctanswer[0].
I'm really in a bit of a hole here and if anyone can help me it would be greatly appreciated.
Many thanks in advance
James