我的剧本:
ob_start();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-type: text/html; charset=utf-8');
include "tilslut.php";
$userid = $_GET["userid"];
$s = mysql_query("SELECT points, lastpoint FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
$tid = time();
mysql_query("UPDATE member_profile set points = points+1, lastpoint=$tid WHERE lastpoint<=$tid-60 AND user_id = '".$userid."'");
$e = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$f = mysql_fetch_array($e);
if (mysql_affected_rows() == 1) {
$s = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
?>
Inserted!
}else{
echo "Already got";
}
ob_flush();
?>
我有这个给点.
更新查询有效,并且仅在lastpoint< = time() - 60时给出点,但即使它没有插入,它仍然会说“已插入”.
我曾尝试使用受mysql影响的行来检查它是否有影响,但这似乎不起作用.
解决方法:
在进行另一次选择之前,必须在更新后立即调用mysql_affected_rows. mysql_affected_rows仅适用于在连接上执行的最后一个查询.
标签:php,mysql
来源: https://codeday.me/bug/20190730/1583257.html