我的脚本:
<?php
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-affected-rows 来检查它是否受到影响,但这似乎不起作用。
最佳答案
您必须在更新后立即调用 mysql_affected_rows,然后再进行另一次选择。 mysql_affected_rows 将仅对连接上执行的最后一个查询起作用。
关于PHP 受影响的行 = 1 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268522/