Jump to content

[SOLVED] Need add a timer


blink359

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/155372-solved-need-add-a-timer/
Share on other sites

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>

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.