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)";
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.