blink359 Posted April 23, 2009 Share Posted April 23, 2009 Hey i was wondering how to put a timer on my php script i also need it to make a popup when they click "vote" here is my PhP script so far i am relitavely new to PhP aswell <?php $dbhost = "127.0.0.1"; //database host goes here $dbuser = "your_user"; //database user goes here $dbpass = "your_password"; //database password goes here $dbname = "world"; //database name goes here mysql_connect($dbhost, $dbuser, dbpass); mysql_select_db($dbname); $user = $_POST['user']; $success = true; $problemMessage = "Cannot connect to mysql server"; if (isset($_POST['Submit']) { if(!$user); { $problemMessage .= "Please enter your account name <br />"; $success = false; } if ($success) { echo ("Thanks for voting!") { mysql_query("INSERT INTO mailbox_insert_queue VALUES('$user','$user','".Thanks for voting."','".Thanks for voting for our server please take this token as a thank you from our staff Thanks from the Sinister WoW team."','61','0','1234500','1')"); //1234500 is the id for our token ?> <html> <head> <title>Voting Page</title> </head> <body> <form> Username: <input name="user" type="text"/><br> <input name="Submit" type="submit" value="Vote" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/ Share on other sites More sharing options...
jonsjava Posted April 23, 2009 Share Posted April 23, 2009 what kind of timer? Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817453 Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 A timer? You should probably use Javascript for this, well depending on what exactly you want you may have to. Just google "javascript timer", and you should find something useful. Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817455 Share on other sites More sharing options...
blink359 Posted April 23, 2009 Author Share Posted April 23, 2009 a timer that doesnt let them have the mysql query done more than once every 12 hours so the mysql queery only sends them one thing untill 12 hours has passed and they vote again Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817457 Share on other sites More sharing options...
FaT3oYCG Posted April 23, 2009 Share Posted April 23, 2009 store the time and date that they access the database and restrict the time by making a query that checks the lat time and if they are allowed then updates it to the new time Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817480 Share on other sites More sharing options...
jonsjava Posted April 23, 2009 Share Posted April 23, 2009 create a column named last_voted. Set it to int(11). Next, modify this code to suit your needs (queries will need to be fixed to reflect your database) <?php $unixts = date("U"); $unix_12hours = date("U") - (12*60*60); $dbhost = "127.0.0.1"; //database host goes here $dbuser = "your_user"; //database user goes here $dbpass = "your_password"; //database password goes here $dbname = "world"; //database name goes here mysql_connect($dbhost, $dbuser, dbpass); mysql_select_db($dbname); $user = mysql_real_escape_string($_POST['user']); $success = true; $problemMessage = "Cannot connect to mysql server"; if (isset($_POST['Submit'])) { if(!$user); { $problemMessage .= "Please enter your account name <br />"; $success = false; } if ($success) { $sql = "SELECT COUNT(*) as `total_users` FROM `users` WHERE `last_voted` <= $unix_12hours AND `username` = $username LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if ($row['total_users'] == 1){ echo ("Thanks for voting!"); mysql_query("INSERT INTO mailbox_insert_queue VALUES('$user','$user','Thanks for voting','Thanks for voting for our server please take this token as a thank you from our staff Thanks from the Sinister WoW team','61','0','1234500','1')"); //1234500 is the id for our token mysql_query("UPDATE `users` SET `last_voted` = $unixts WHERE `username` = '$user' LIMIT 1;"); } else{ $problemMessage = "You have voted in the past 12 hours"; } } } ?> <html> <head> <title>Voting Page</title> </head> <body> <form> Username: <input name="user" type="text"/><br> <input name="Submit" type="submit" value="Vote" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817494 Share on other sites More sharing options...
blink359 Posted April 23, 2009 Author Share Posted April 23, 2009 Hey thanks jonsjava so i just need to use that script and it will work then ? Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817504 Share on other sites More sharing options...
jonsjava Posted April 23, 2009 Share Posted April 23, 2009 as I said, you'll need to fix the SQL that I wrote to match your database, but other than that, yes. It will set up a timer. I didn't write the redirect, though. Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817506 Share on other sites More sharing options...
blink359 Posted April 23, 2009 Author Share Posted April 23, 2009 Just to check what parts i need to edit as im pretty new and i dont wanna muck it up Quote Link to comment https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/#findComment-817516 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.