Kane250 Posted May 4, 2008 Share Posted May 4, 2008 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! Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 6, 2008 Share Posted May 6, 2008 Not sure what you want. Just try my best. Is this what you want? <?php if($_SERVER['REQUEST_METHOD'] == "POST") { echo "[something to stop the timerscript.]"; } ?> Quote Link to comment Share on other sites More sharing options...
Kane250 Posted May 6, 2008 Author Share Posted May 6, 2008 That's along the lines of something I'm looking for, but I still don't know what the code should be. Since POST reloads the page, I want the timer to either stop in place or disappear on reload rather than restart its countdown... Thanks! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 7, 2008 Share Posted May 7, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.