0

I've done quite a bit of google search on this topic, and I can't find an answer. So, I'm making a small website, that visitors will register and submit into database. Then after 2 days, it will automatically delete itself from database if the user not active (If active == 0). I have tried all I could, but I can't figure out how to do it.

Any help would be much appreciated! Thanks!

owebindex
  • 17
  • 4
  • 2
    with cron job . – Mohammad Feb 13 '17 at 15:04
  • What is the triggering event? Time? databases can't run code without a trigger so you need a scheduler, to do it, or when someone hits the website, it runs logic that checks to see if a user has been inactive for more than 2 days and then deletes. But you MUST have a triggering event. Perhaps once a day a cron job runs to check, perhaps every hour it runs. but you need something to "start" the event. – xQbert Feb 13 '17 at 15:09
  • how to implement cron into it? – owebindex Feb 13 '17 at 15:09

1 Answers1

0

You could set up an automated procedure (e.g. a CRON job) to detect the active status of users and remove if necessary.

This depends on the coding language so given the tags in your question you are using php and mysql. First of all you will need to store a datetime stamp in your users table. You could then create a php file that would check the users table and compare the current system date with the datetime stamps. If the difference is greater than two days then delete that user; if not then do nothing.

Hope this helps.

asugrue15
  • 65
  • 1
  • 8
  • For information on creating a cron job in php the following answer may help you http://stackoverflow.com/a/24625097/5341620 – asugrue15 Feb 13 '17 at 15:28