Php 多个mysql\u查询不工作

Php 多个mysql\u查询不工作,php,mysql,Php,Mysql,我有一个有效的mysql\u查询: 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 di

我有一个有效的mysql\u查询:

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())); 

那么,我错过了什么吗?

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

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 `buyers` = `buyers` + $qtd, 
`pending` = `pending` - $qtd 
WHERE `id` = $pid")  or die (pgs_log("erro linha 70 >".mysql_error()));

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

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

如果您想再次检查您的更新是否确实更新了数据,那么您应该进行调查。不过,您需要检查旧值是否与新值不同,否则将没有受影响的行,这将使它成为一个无用的检查

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

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

如果您想再次检查您的更新是否确实更新了数据,那么您应该进行调查。不过,您需要检查旧值是否与新值不同,否则将没有受影响的行,这将使它成为一个无用的检查

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

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

尝试将
sql查询回显到屏幕上,查看
$qtd
$pid
是否仍在工作,如果仍在工作,请检查您的
pgs_日志
(不确定它的作用)。查询是否给出并出错,或者页面只是加载数据库,但数据库没有更改?如果代码中存在SQL注入漏洞,请将
where id=$pid”)
更改为
where id='$id')
。i、 e.将所有
$vars
用单引号括起来,否则您的
mysql\u real\u escape\u字符串将无效。尝试
sql查询回送到屏幕上,查看
$qtd
$pid
是否仍在工作,如果不工作,请检查
pgs\u日志
(不确定它做了什么)。查询是否给出并出错,或者页面只是加载数据库,但数据库没有更改?如果代码中存在SQL注入漏洞,请将
where id=$pid”)
更改为
where id='$id')
。i、 e.将所有的
$vars
用单引号括起来,否则您的
mysql\u real\u escape\u字符串将无效。