I started to write a script that checks the user’s registration date in the database and if the user “expired” the script blocks his access to the site. The script should run automatically every day (cron job?) And repeat the same process every time.
Unfortunately for some reason UPDATE function does not work and I don`t understand why.
Thanks in advance!
THE CODE:
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
$sql=" SELECT id, group_id, registerDate
FROM w9phl_users
INNER JOIN w9phl_user_usergroup_map ON w9phl_users.id = w9phl_user_usergroup_map.user_id
WHERE registerDate < NOW( )
AND group_id = 3
";
$result=mysql_query($sql);
if (!$result) {
die('Could not query:' . mysql_error());
}
while ($details = mysql_fetch_assoc($result)) {
if ($details['id'] > 904)
{$sql=" UPDATE w9phl_users
SET block=1
WHERE id > 904";
}
else
{
echo "only IDs greater than 904 is permitted.";
}
}
Your forgot to run your query. You just saved it in a variable, but didn’t execute.