Jump to content

[SOLVED] Delete user after 72 hours


studgate

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/136127-solved-delete-user-after-72-hours/
Share on other sites

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);';

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(); ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.