`id, question, option1, option2, option3, option4, correct`. i retrieve all the questions and options from this table through following php code
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<p>
<form name="form1" method="post" action="quiz2action.php">
<?php
$db = mysql_connect("localhost");
mysql_select_db("videoshop", $db);
$queryquestions = "SELECT * FROM quiz" or die();
$resultquestions = mysql_query($queryquestions) or die();
while($rowquestions = mysql_fetch_array($resultquestions))
{
$questionid = $rowquestions['id'];
$question = $rowquestions['question'];
$answerone = $rowquestions['option1'];
$answertwo = $rowquestions['option2'];
$answerthree = $rowquestions['option3'];
$answerfour = $rowquestions['option4'];
echo "
<b>Question $questionid: $question</b><br>
<input type='radio' name='".$questionid."' value='".$answerone."'>".$answerone."<br>
<input type='radio' name='".$questionid."' value='".$answertwo."'>".$answertwo."<br>
<input type='radio' name='".$questionid."' value='".$answerthree."'>".$answerthree."<br>
<input type='radio' name='".$questionid."' value='".$answerfour."'>".$answerfour."<br>";
echo "<br><br>";
}
?>
</p>
<label>
<input type="submit" name="button" id="button" value="Submit">
</label>
</form>
<p> </p>
</body>
</html>
Code: Select all
$questionid=(isset($_POST['$questionid']))?$_POST['$questionid']:"";
$answerthree=(isset($_POST['$answerthree']))?$_POST['$answerthree']:"";
$db = mysql_connect("localhost");
mysql_select_db("videoshop", $db);
$query = "SELECT * FROM quiz WHERE id = ".$questionid." and correct = ".$answerthree."";
echo $query;
$result = mysql_query($query);
$score = 0;
if($result)
{
$score++;
}