Jump to content

need help in php script


doforumda

Recommended Posts

i have a quiz website and timer script js. what i want is when the user starts quiz, countdown of five minutes will also start. user will hhave to complete quiz in five mins. if user does not succeed to complete in given time then user will automatically taken to next page and his score will shown to him.

 

i already have scripts for both quiz and timer but i dont know how do i integrate them and how to take user to next page. my code is here

 

quiz.php

<!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>
<div id = "time"></div>

<script type = "text/javascript">

function display(secs) {
if (secs <= 0) { 
alert("Your time is up!");
return;
}
secs--;
document.getElementById("time").innerHTML = "You have " +
Math.floor(secs/60) + ":" + (secs % 60 < 10 ? "0" : "" ) + (secs % 60) + " left";
setTimeout("display("+secs+")",1000);
}

display(301); // 300 seconds = 5 minutes

</script>
<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=\"question[$questionid]\" value=\"1\"> $answerone <br>
   <input type=\"radio\" name=\"question[$questionid]\" value=\"2\"> $answertwo <br>
   <input type=\"radio\" name=\"question[$questionid]\" value=\"3\"> $answerthree <br>
   <input type=\"radio\" name=\"question[$questionid]\" value=\"4\"> $answerfour <br>";
   
   echo "<br><br>";
}

?>
</p>

  <label>
  <input type="submit" name="button" id="button" value="Submit">
  </label>
</form>
<p> </p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/177307-need-help-in-php-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.