需要有关多个 WHERE 子句的帮助
我有一个想要执行的 UPDATE 查询。
但在我们更新数据库中的数量之前,需要满足两个条件。
首先,session_id() 必须与 sessionid 列中的一个 sessionid 匹配,其次,产品的描述必须与该 sessionid 对应的产品描述匹配。
这就是我所拥有的:
mysql_query(UPDATE cart
SET quantity = $q,
WHERE sessionid = "'.session_id().'"
AND description = $d') or die(mysql_error());
现在,它给了我以下错误:
您的 SQL 语法有错误;
检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 'WHERE sessionid="bqlbh5rdogbhmq70skhtkbvmb0" AND description=$d' 附近使用的正确语法
但是,我直接从 W3Schools 复制了此更新查询,因此它必须是正确的, 正确的?任何帮助将不胜感激。
I have an UPDATE query I'd like to perform.
But there need to be 2 conditions met before we can update a quantity in the database.
First, the sessions_id() must match one of the sessionid's in the sessionid column, and second, the Description of the product must match the description of the product corresponding to the sessionid.
Here's what I have:
mysql_query(UPDATE cart
SET quantity = $q,
WHERE sessionid = "'.session_id().'"
AND description = $d') or die(mysql_error());
Now, it is giving me the following error:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE sessionid="bqlbh5rdogbhmq70skhtkbvmb0" AND description=$d' at line 1
However, I have copied this update query straight from W3Schools, so it must be correct, right? Any help at all would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
另外,这里的单引号有问题
.'" AND description=$d')
并且 $d 未被解析。这将导致错误的 SQL 查询。将单引号更改为双引号,或者仅使用字符串附加
.
来附加$d
的值,而不是文字 $d示例:
Also you have problem with the single quotes here
.'" AND description=$d')
and $d is not parsed. This will result wrong SQL query.Change the single quotes to double quotes or just use string append
.
to append the value of$d
, not the literal $dexample :
发生错误的原因是 WHERE 语句之前的“,”符号。正确的查询是:
mysql_query( "UPDATE cart SET amount = " . $q . " WHERE sessionid = "' . session_id( ) . '" AND description = " . $d . "" ) 或 die( mysql_error ( ) );
The error occurs because of the ',' sign before the WHERE statement. The correct query would be:
mysql_query( "UPDATE cart SET quantity = " . $q . " WHERE sessionid = "' . session_id( ) . '" AND description = " . $d . "" ) or die( mysql_error( ) );
删除
$q
后面的,
(逗号)remove the
,
(comma) after$q
您粘贴的代码格式错误,我怀疑您的应用程序中使用的代码。
the code you have pasted is badly formatted, and i doubt the code used in your app.
它应该看起来像这样:
It should look that way: