-1

我开始编写一个脚本来检查用户在数据库中的注册日期,如果用户“过期”,该脚本会阻止他访问该站点。该脚本应该每天自动运行(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.";
  }     


}
4

1 回答 1

1

您忘记运行查询。您只是将它保存在一个变量中,但没有执行。

$sql = "UPDATE w9phl_users
        SET block=1 
        WHERE id > 904";
mysql_query($sql);
于 2012-12-09T13:50:13.950 回答