多个 mysql_query 不起作用

发布于 2024-11-09 11:44:38 字数 388 浏览 0 评论 0原文

我有一个有效的 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 技术交流群。

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

发布评论

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

评论(3

凡尘雨 2024-11-16 11:44:38

有几件事。首先,您不需要为此进行两个单独的查询。 MySQL 可能会因为破折号而误认为你的值是列名:

mysql_query("
UPDATE `products` 
SET `buyers` = `buyers` + $qtd, 
`pending` = `pending` - $qtd 
WHERE `id` = $pid")  or die (pgs_log("erro linha 70 >".mysql_error()));

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_query("
UPDATE `products` 
SET `buyers` = `buyers` + $qtd, 
`pending` = `pending` - $qtd 
WHERE `id` = $pid")  or die (pgs_log("erro linha 70 >".mysql_error()));
揽清风入怀 2024-11-16 11:44:38

如果您想仔细检查您的更新是否确实更新了数据,那么您应该调查 mysql_affected_rows。不过,您需要检查旧值是否与新值不同,否则受影响的行数将为零,从而使其成为无用的检查。

您没有在表和列引用周围使用正确的引用。这些应该用反勾号包围,并且可以组合起来,如下所示:

UPDATE
    `products` 
SET
    `pending` = `pending` - $qtd,
    `buyers` = `buyers` + $qtd
WHERE
    `id` = $pid;

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:

UPDATE
    `products` 
SET
    `pending` = `pending` - $qtd,
    `buyers` = `buyers` + $qtd
WHERE
    `id` = $pid;
反差帅 2024-11-16 11:44:38
mysql_query("update `products` 
             set `pending` = `pending` - $qtd, 
                 `buyers` = `buyers` + $qtd 
             where `id` = $pid")  
             or die (pgs_log("erro linha 70 >".mysql_error())); 
mysql_query("update `products` 
             set `pending` = `pending` - $qtd, 
                 `buyers` = `buyers` + $qtd 
             where `id` = $pid")  
             or die (pgs_log("erro linha 70 >".mysql_error())); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文