I'm trying to delete a row in my table after 1 minute (for test) since it was inserted. In MySql, I found a way to do this, but it is not working.
The code:
// starting and getting the session ID
session_start();
$session = session_id();
// get the timestamp
$date = date_create();
$time = date_timestamp_get($date);
// create the timestamp with the variation of 1 minute
$time_check = $time + 1;
// inserting the session ID with the current time
$sql1 = "INSERT INTO $tbl_name(session, time) VALUES ('$session', '$time')";
$connect->query($sql1);
Until know, everything works fine. After the code above, I'm trying the delete thing:
$sql2 = "DELETE FROM $tbl_name WHERE time < $time_check";
$connect->query($sql2);
I saw another approach in a tutorial (see it here). I was trying to understand the code above and also trying to see another option, like creating an event with MySql:
$sql2 = "CREATE EVENT clearSession
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
DO DELETE FROM $tbl_name where session = $session";
$connect->query($sql2);
I would like to know where is the mistake.