Jump to content

Avoiding a timer reset?


Kane250

Recommended Posts

Hi,

 

I'm working on a quiz game that has a 10 second timer, after which the page is set to redirect to the next question after 10 seconds as well. However, I also have some php going on which makes text appear after people answer questions in text boxes after POST (which essentially reloads the page, and restarts the timer).

 

Any idea how I can rework the timer so it just disappears after POST is submitted?

 

Here is my code in case it helps.

 

<html>
<head>

<meta http-equiv="refresh" content="10;url=imagetest2.php">

<script type="text/javascript" src="CountDown.js"></script>
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 10);
}
</script>
<style type="text/css">
#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}
</style>

</head>


<body>

<img src="/images/imagetest1.png"><br />

Time remaining: <span id="CountDownPanel"></span>

<?php

//CONNECT TO MYSQL & THE DATABASE
$link = mysql_connect('localhost', 'user', 'pw');

$dbselected = mysql_select_db('user', $link);

//SELECT STATEMENT TO GET RANDOM DATA
$randomselect = mysql_query("SELECT highlowincome FROM responses ORDER BY RAND() LIMIT 0,1;") or die (mysql_error());

//SET VARIABLES FOR THE USERS RESPONSE AND THE RANDOM RESPONSES
$userresponse = $_POST['userresponse'];

$res = mysql_fetch_assoc($randomselect);
$randomanswer = $res['highlowincome'];

//PRINT OUT THE RESPONSE USING BOTH VARIABLES
print "<pre>";
print "Your Response: <b>$userresponse</b> Associates Most With Those Of <b>$randomanswer</b>.";
print "</pre>";

?>

<form method="POST" action="imagetest1.php" />
<input type='text' value="" name="userresponse" /><br />
<br />
<input type='submit' value="Submit Answer" name="submit" /><br />
</form>

<a href="imagetest2.php">Next Image</a>

</body>
</html>

 

Really appreciate any help you can offer...I'm so stuck on this one!

Link to comment
https://forums.phpfreaks.com/topic/104116-avoiding-a-timer-reset/
Share on other sites

just put the

if($_SERVER['REQUEST_METHOD'] != "POST")

around anything you don't want to happen when there is a post....

 

<html>
<head>

<meta http-equiv="refresh" content="10;url=imagetest2.php">
<?php if($_SERVER['REQUEST_METHOD'] != "POST") { ?>
<script type="text/javascript" src="CountDown.js"></script>
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 10);
}
</script>
<style type="text/css">
#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}
</style>
<?php } ?>

</head>


<body>

<img src="/images/imagetest1.png"><br />

<?php
if($_SERVER['REQUEST_METHOD'] != "POST")
  print 'Time remaining: <span id="CountDownPanel"></span>';

//CONNECT TO MYSQL & THE DATABASE
$link = mysql_connect('localhost', 'user', 'pw');

$dbselected = mysql_select_db('user', $link);

//SELECT STATEMENT TO GET RANDOM DATA
$randomselect = mysql_query("SELECT highlowincome FROM responses ORDER BY RAND() LIMIT 0,1;") or die (mysql_error());

//SET VARIABLES FOR THE USERS RESPONSE AND THE RANDOM RESPONSES
$userresponse = $_POST['userresponse'];

$res = mysql_fetch_assoc($randomselect);
$randomanswer = $res['highlowincome'];

//PRINT OUT THE RESPONSE USING BOTH VARIABLES
print "<pre>";
print "Your Response: <b>$userresponse</b> Associates Most With Those Of <b>$randomanswer</b>.";
print "</pre>";

?>

<form method="POST" action="imagetest1.php" />
<input type='text' value="" name="userresponse" /><br />
<br />
<input type='submit' value="Submit Answer" name="submit" /><br />
</form>

<a href="imagetest2.php">Next Image</a>

</body>
</html>

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.