delete records older than 1 hour
Posted on 2012-08-14
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)";