Link to home
Start Free TrialLog in
Avatar of Wanda Marston
Wanda MarstonFlag for Canada

asked on

I want to delete potential users from the database automatically if they have not activated their account.

At this point users register and then an email is sent to them. So their information is in the database. There is a link in the database that they click and then that changes their input in the "active" column to NULL. They then can log in to their account if the active column says Null. Many registrants do not active their account. I also feel that some of these registrants are FAKE users so it is possible that their email is phony. IF A CAPTCHA is the answer then I would prefer not to use the image style CAPTCHA. I personally do not like to use those when I am trying to get into a website.

The code I am now using.
     $q = "INSERT INTO users (username, email, pass, first_name, mid_initial, last_name, active, agree, date_expires) VALUES (?, ?, ?, ?, ?, ?, ?,  'Agree',  DATE_ADD(NOW(), INTERVAL 2 YEAR) )";      
                
// Prepare the statement:
$stmt = mysqli_prepare($db, $q);

// Bind the variables:
mysqli_stmt_bind_param($stmt, 'sssssss', $u, $e, $p, $fn, $mi, $ln, $a);

// Assign the values to variables:
$u  = $_POST['username'];
$e  = $_POST['email'];
$fn  = $_POST['first_name'];
$mi = $_POST['mid_initial'];
$ln  = $_POST['last_name'];
//$a  = $_POST['active']; 
            
// Execute the query:
 mysqli_stmt_execute($stmt); 
                       
// Send the email:
                $body = "Thank you for registering at Tired Of Being Ripped Off. To activate your account, please click on this link:\n\n";
                $body .= BASE_URL . 'ActivateLU.php?x=' . urlencode($e) . "&y=$a";
                mail($trimmed['email'], 'Registration Confirmation', $body, 'From: admin@tiredofbeingrippedoff.com');
// Finish the page:
               include('ThankYou.html'); // Include the Thank You For Registering
                exit(); // Stop the page.  

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

OK, then delete them.  Not sure I understand your question.

I'm assuming you want to delete them after some period of time.

You'll need some sort of a last_login date somewhere.

Then it's simple date interval against that column and where active='Active' or a simple 'is not null'.
Wrong workflow. The account is created only if the e-mail recipient responded to the e-mail. Prior to that you have a table to store pending activations with a date column to determine the age of each entry. Then a daily job deletes outdated entries.
Avatar of Wanda Marston

ASKER

Okay can I just add a daily job to the table where the users are stored right now and the outdated entries deleted?

Can someone send me the code for this?
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all for your comments and I will be testing some things out very soon.

I am on a Mac, just so you know.

I also use PHPMyAdmin through my web hosting and had previously checked out using Even Scheduler but I believe my Web Hosting company said that this feature was not available me.

 I will get back to you all.
Yes this often the case hosting company does not allow to use Event Scheduler and often limit the use of Cronjob so sometimes the only option is to trigger manually the link of the function or use an online service like
https://cron-job.org/en/ 
All the experts were very helpful. My question could have had several different approaches to resolving it.

Thanks