-2

I have made a log in system which asks for email activation. It all works fine. However, there is no real 'spam' protection. When the user creates an account, it inserts a row with the column 'activated' = 'NO'.

I want to make it so that if the user hasn't activated their account with, let's say, 3 hours, it will delete the row from the MySQL database. I have made a cron job which runs the following every 30 mins.

<?php

ob_start();
include 'global.php';
ob_end_clean();

$check_times = (time() - ('-3 hours'));
$query = "SELECT * FROM users WHERE time<=$check_times and activated='NO'";
$result = mysql_query($query) or trigger_error(mysql_error().$query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$inactive_user = $row['username'];

echo $inactive_user;
echo "<br>";
echo $check_times;
?>

The 'global.php' is connecting to the database. The above code works but only for one row (IT ONLY RETURNS THE VALUE OF THE FIRST INSTANCE IT COMES ACROSS)

I have looked into 'Do While' and 'Loop Until' and whatever but don't know what to put in the brackets...Do While (//what do I put in here?)

At the moment, the code only echos out the instances but I will change that to delete

4

2 回答 2

0
while($row = mysql_fetch_array($result)) {
    $inactive_user = $row['username'];
}

Additionally, you should phase out the use of mysql_ functions, and look into mysqli as a replacement - mysql_ is deprecated.

于 2013-06-06T17:16:44.303 回答
0

You insert all the usernames inside $inactive_user[].

    $inactive_user = array();
while($rows = mysqli_fetch_array($result){
    $inactive_user[] = $rows['username'];
}

And then loop the array and echo every user:

foreach($inactive_user as $us){
    echo $us;
}

As mysql is deprecated, you should use mysqli or PDO

于 2013-06-06T17:16:46.173 回答