我准备的声明更新存在问题

发布于 2024-08-11 15:35:55 字数 417 浏览 3 评论 0原文

$query = "UPDATE kids_entry SET entries=? WHERE parentsemail=?";
$stmt1 = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt1, 'is',$entries,$parentsemail);
mysqli_execute($stmt1);
if(mysqli_stmt_affected_rows($stmt1) != 1)
    die("issueasdass"); 
mysqli_stmt_close($stmt1);

上面的代码在另一个页面上确实对我有用,但我似乎无法让它在这里工作。在另一页上,要更新的设置是硬编码的并且不是动态的,因此这可能就是它对我不起作用的原因。有人可以告诉我我做错了什么吗?谢谢

$query = "UPDATE kids_entry SET entries=? WHERE parentsemail=?";
$stmt1 = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt1, 'is',$entries,$parentsemail);
mysqli_execute($stmt1);
if(mysqli_stmt_affected_rows($stmt1) != 1)
    die("issueasdass"); 
mysqli_stmt_close($stmt1);

The above code does work for me on another page but i cannot seem to get it to work here. On the other page the set to update is a hardcoded in and is not dynamic so that might be why it isn't working for me. Can someone tell me what I am doing wrong? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白馒头 2024-08-18 15:35:55

条目的值是否可能与数据库中已有的值相同?我认为如果没有任何变化,*_affected_rows 不会返回 1。是否可能有超过 1 个“parentsemail”条目?那么也许 mysqli_stmt_affected_rows 会返回类似 2 的内容?也许让我们知道 mysql_stmt_affected_rows 正在返回什么,而不是检查 1。例如,来自文档:

大于零的整数表示
受影响的行数或
检索到。零表示没有
更新的记录
UPDATE/DELETE 语句,无行
与查询中的 WHERE 子句匹配
或者还没有查询
被执行。 -1表示查询
返回了一个错误。

Is it possible that entries is the same value as what's already in the database? I don't think *_affected_rows returns 1 if nothing changes. Is it possible that there's more than 1 entry for 'parentsemail'? So perhaps mysqli_stmt_affected_rows is returning something like 2? Instead of checking 1, maybe let us know what mysql_stmt_affected_rows is returning. For example, from the docs:

An integer greater than zero indicates
the number of rows affected or
retrieved. Zero indicates that no
records where updated for an
UPDATE/DELETE statement, no rows
matched the WHERE clause in the query
or that no query has yet been
executed. -1 indicates that the query
has returned an error.

深海里的那抹蓝 2024-08-18 15:35:55

这个问题似乎已经自行解决。没有任何改变,但现在可以了!

The issue appears to have resolved itself. Nothing has changed but now it works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文