Page 1 of 1

need help in making quiz

Posted: Fri Oct 09, 2009 9:44 am
by doforumda
hi i want to make an mcq quiz. what i have done sofar is i make mysql table called `quiz` in this table i have following columns
`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>&nbsp;</p>
</body>
</html>
 
now when the user selects answer and click on submit then it should go and check the correct answer in the table from column `correct`. if the answer selected by the user is the same as in column correct then increase the user score by 1. i am trying all this in the following code but it is not working. can anyone help me

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++;
}

Re: need help in making quiz

Posted: Fri Oct 09, 2009 11:58 am
by doforumda
I am waiting for help. anybody

Re: need help in making quiz

Posted: Fri Oct 09, 2009 12:18 pm
by desperado
is the correct answer always $answerthree ?

Re: need help in making quiz

Posted: Fri Oct 09, 2009 12:45 pm
by Mirge
doforumda wrote:I am waiting for help. anybody
Wait longer than 2 hours to bump your threads. :banghead:

Re: need help in making quiz

Posted: Fri Oct 09, 2009 10:40 pm
by doforumda
no desperado answer could could be any option

Re: need help in making quiz

Posted: Sat Oct 10, 2009 5:51 am
by doforumda
any expert here who can solve my problem

Re: need help in making quiz

Posted: Tue Oct 13, 2009 2:38 pm
by desperado
$query = "SELECT * FROM quiz WHERE id = ".$questionid." and correct = ".$answerthree."";

looks to me like it's always answerthree.