我有一个名为“up票”的数据库列。我有另一列名为"userid“。
我希望在与我所提供的动态变量匹配的“更新”列中增加值。
以下是我的尝试:
$results = $wpdb->query("UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d", $theDynamicUserID);这将导致以下错误:
[You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%d' at line 1]
UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d编辑:这些Stack帖子似乎暗示了这是可能的,但我无法正确地理解语法:https://stackoverflow.com/questions/973380/sql-how-to-increase-or-decrease-one-for-a-int-column-in-one-command
https://stackoverflow.com/questions/2259155/increment-value-in-mysql-update-query
发布于 2021-05-10 12:39:52
只是注意到你错过了准备。
您的代码应该如下所示
$results = $wpdb->query($wpdb->prepare('UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d', $theDynamicUserID));发布于 2021-05-10 12:37:41
编辑:看起来这是个坏主意:
我似乎已经通过构建查询来解决这个问题,如下所示:
$theQuery = "UPDATE points SET upvotes = upvotes + 1 WHERE userid = '".$theDynamicUserID."'";
$results = $wpdb->query($theQuery);https://wordpress.stackexchange.com/questions/387969
复制相似问题