多个 mysql_query 不起作用
我有一个有效的 mysql_query:
mysql_query("update products set buyers = buyers+$qtd where id=$pid") or die (pgs_log("erro linha 70 >".mysql_error()));
但是我在它后面插入以下查询,它只执行第一个查询:
mysql_query("update products set pending = pending-$qtd where id=$pid") or die (pgs_log("erro linha 70 >".mysql_error()));
那么,我错过了什么吗?
I have a working mysql_query:
mysql_query("update products set buyers = buyers+$qtd where id=$pid") or die (pgs_log("erro linha 70 >".mysql_error()));
But then I insert the following query right after it, and it only execute the first one:
mysql_query("update products set pending = pending-$qtd where id=$pid") or die (pgs_log("erro linha 70 >".mysql_error()));
So, am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几件事。首先,您不需要为此进行两个单独的查询。 MySQL 可能会因为破折号而误认为你的值是列名:
Couple of things. First off you don't need two separate queries for this. MySQL may be confused into thinking your value is a column name because of the dash:
如果您想仔细检查您的更新是否确实更新了数据,那么您应该调查 mysql_affected_rows。不过,您需要检查旧值是否与新值不同,否则受影响的行数将为零,从而使其成为无用的检查。
您没有在表和列引用周围使用正确的引用。这些应该用反勾号包围,并且可以组合起来,如下所示:
f you wanted to double check that your update actually updated the data then you should investigate mysql_affected_rows. You'll need to check that your old value was different to your new value though, otherwise you'll have zero affected rows, making it a useless check.
You don't use proper quoting around the table and column references. These should be surrounded with back ticks, and could be combined, like the following: