php - Automatically delete record when past current timestamp or date


I'm coding a password recovery script. When the user want's to recover his password, a 50 string of random validation code is being written into the database, which will be used as$_GET to validate.

This table calledrecovery isvar(50) andunique. After accepting the link, this field will be erased. But what if the user is not going to click the link? This has to be deleted from the database, because the chance that this random 50 string will be created gets bigger and the database gets unnessessary data.

I've been looking around and saw this:

INSERT INTO what_ever ('', '', now(), DATE_ADD(NOW(), INTERVAL 3 DAY));

This way I enter an expiration date, but how can MYSQL delete this himself when the time is right? Is that even possible?

If not, what's my best option here?


Of course 3 days is too much. I was thinking about 15 minutes.




You can write a trigger that deletes old data when inserting new rows.

If you don't know how to write a trigger, use an advanced MySQL client like HeidiSQL, it will help you with some GUI.




You could put a trigger on insert to the database to delete any records older than a certain amount.

People are also looking for solutions to the problem: php - Can anyone help me with syntax?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.