データベース内のユーザーの登録日をチェックするスクリプトの作成を開始し、ユーザーが「期限切れ」の場合、スクリプトはサイトへのアクセスをブロックします。スクリプトは毎日自動的に実行され (cron ジョブ?)、毎回同じプロセスが繰り返されます。残念ながら、何らかの理由で UPDATE 機能が機能せず、その理由がわかりません。前もって感謝します!
コード:
// 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.";
}
}