0
<?php
define('INCLUDE_CHECK',true);
error_reporting(0);
session_name('tzLogin');
session_start();
$user = $_SESSION['name'];

if($user or die('Please login to continue')) {      

   mysql_connect("localhost","root","password");
   mysql_select_db('db_account');
   require_once 'Functions/Import.php';



   $l = isset ( $_GET [ 'l' ] ) ? $_GET [ 'l' ] : null ;


   if ( ! is_null ( $l ) ) {
$gd= mysql_query("SELECT * FROM t_account WHERE name='$user' AND (now() - INTERVAL 6 HOUR > lastvoted)");

          if($gd or die("Come back later you still have time left to vote"))
          {
$qry = "UPDATE t_account SET `vo` = `vo` + 1, `lastvoted` = now() WHERE name='$user'";
$result = @mysql_query($qry);
}
else {

}
          header ( 'Location: ' . base64_decode ( $l ) , true , 301 ) ;

          exit ;

    }

        }
?>

I am not getting the required result.

Hm ive tried what you have told me to and i made the code this way

but still the query is getting executed instead of giving the msg "come back later" the query should only work if the stored time is 6 hour earlier to the live time

:( please help me out

1 Answers1

0

Your query is outright false. date() in MySQL does not "format" a date value into a string as it does in PHP. MySQL's date() extracts the date portion of a datetime value and returns it as a string, e.g.

date('2013-04-21 12:00:00') -> '2013-04-21'

Do NOT mix php and mysql date logic like that. MySQL is perfect well capable of generating "now" dates, via now() and CUR_DATE and various other functions.

SELECT ... WHERE (now() - INTERVAL 6 HOUR > lastvoted)

UPDATE ... `lastvoted` = now()

is all you need.

Marc B
  • 356,200
  • 43
  • 426
  • 500