studgate Posted December 8, 2008 Share Posted December 8, 2008 Hi Guys, I am trying to automatically deleting users that have not activated their account after 72 hours. How can I go about doing that?? There are two fields in the database that I want to to check: if active (int) = 0 (not active) or 1 (active) and compare the date_registered(timestamp) with 72 hours. Any ideas are welcome, thanks in advance guys. Quote Link to comment https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/ Share on other sites More sharing options...
trq Posted December 8, 2008 Share Posted December 8, 2008 Easiest way way be to execute a cron job every hour, something like.... 0 * * * * /usr/bin/mysql -uYOURUSERNAME -pYOURPASSWORD YOURDATABASE -e 'DELETE FROM tbl WHERE date_registered < DATE_SUB(NOW(), INTERVAL 72 HOURS);'; Quote Link to comment https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/#findComment-709929 Share on other sites More sharing options...
studgate Posted December 8, 2008 Author Share Posted December 8, 2008 I was thinking about a function that runs on all pages and in the backend... it will connect to the database, check if status = 0 and date_registered is > 72 hours. if both conditions are met, delete the user. Quote Link to comment https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/#findComment-709939 Share on other sites More sharing options...
trq Posted December 8, 2008 Share Posted December 8, 2008 I was thinking about a function that runs on all pages and in the backend... it will connect to the database, check if status = 0 and date_registered is > 72 hours. if both conditions are met, delete the user. No point running an extra query on every page if you don't need to but yeah... if you don't have access to cron I guess thats an option. ps: I forgot the status check in my query. 0 * * * * /usr/bin/mysql -uYOURUSERNAME -pYOURPASSWORD YOURDATABASE -e 'DELETE FROM tbl WHERE status = 0 && date_registered < DATE_SUB(NOW(), INTERVAL 72 HOURS);'; Quote Link to comment https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/#findComment-709940 Share on other sites More sharing options...
studgate Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks Thorpe, there was one mistake in your query, 72 HOUR not 72 HOURS/ Okay I create a function that will do that for me in the backend or any page that you want. Here it is for all who needs something like this. function DeleteInactiveUsers(){ $sql = 'DELETE FROM users_table WHERE status = 0 && registered_date < DATE_SUB(NOW(), INTERVAL 72 HOUR);'; mysql_query($sql) or die('The MySQL query failed. MySQL said: '.mysql_error()); } You can just call this on the page that you want: <? DeleteInactiveUsers(); ? Quote Link to comment https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/#findComment-709961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.