Link to home
Start Free TrialLog in
Avatar of web5dev7
web5dev7

asked on

delete records older than 1 hour

Hi,

When a user submits a form, I am trying to delete all previous records older than 1 hour. So right after my insert statement I am adding a delete statement.  My date field is named "added_on" and the date values look like 2012-07-31 21:45:03.  Using the below deletes everything including the current record, instead of the records older than 1 hour.

$sql = "INSERT INTO info_requests SET
email = '".addslashes($data['email'])."',
ip_address = '".$_SERVER['REMOTE_ADDR']."',
added_on = now() ";

$sql = "DELETE FROM info_requests WHERE added_on < (now() - interval 1 hour)";
ASKER CERTIFIED SOLUTION
Avatar of Lara F
Lara F
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of web5dev7
web5dev7

ASKER

Thanks all!  Yes there may well be something about timezone difference between my location and server?  

The data is being collected at a very low activity kiosk site so we decided it was better to schedule a Cron job to empty records twice a day - since it would likely be more dependable/frequent than the next user.  The data was only being used for temporary validation and so we do not want to store it beyond its usefullness.

The Cron is working as desired, but I'll still experiment with your suggestions to see if I can solve the mystery.