PHP 受影响的行 = 1 无法正常工作

标签 php mysql

我的脚本:

<?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/

相关文章:

php - 在 JavaScript 警报/确认框中发送 PHP 变量

php - while 循环中的 while 循环

python - 提高python中的插入速度

php - MySQL EXISTS 返回 1 或 0

php - 创建 PHP 多维关联数组的 Javascript 版本

php - set_time_limit(),Die()这个函数可以用来取消php中的文件上传吗

php - 无法比较 php 中的查询结果

javascript - 对数据库的多次调用无法正常工作

MySQL创建新用户撤销对某些数据库的访问权限

php循环记录集直到