Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,如何在每次订购物品时将数量减少1?_Php - Fatal编程技术网

在PHP中,如何在每次订购物品时将数量减少1?

在PHP中,如何在每次订购物品时将数量减少1?,php,Php,第二个查询中有一个`字符,您不能输入 $query1=mysql_query("SELECT Quantityy FROM `corro`.`food` where `food`.`id` LIKE $id"); $rows = array(); while($r = mysql_fetch_assoc($query1)) { $output = $r['Quantityy']; //encode the returned data in JSON format

第二个查询中有一个`字符,您不能输入

$query1=mysql_query("SELECT Quantityy FROM `corro`.`food` where  `food`.`id` LIKE $id");
$rows = array();

while($r = mysql_fetch_assoc($query1)) {

    $output = $r['Quantityy'];

        //encode the returned data in JSON format
        echo $output;
        $query2=mysql_query("UPDATE food SET Quantityy = Quantityy - 1` where  `food`.`id` LIKE $output");
}

?>
在循环中:

$query1=mysql_query("SELECT Quantityy,id FROM `corro`.`food` where  `food`.`id` LIKE $id");

请检查拼写…

您的SQL似乎到处都是,并且存在由随机倒勾引起的语法错误。请尝试使用一条单条SQL语句,而不是运行循环:

$query2=mysql_query("UPDATE food SET Quantityy = Quantityy - 1 where  `food`.`id` LIKE ".$r["id"]);
另外,当您可以使用
=
时,为什么要像
一样使用


在循环内部,您也在按数量引用
食品
id
列?

在编码中有一个错误,我无法确定完整的应用程序是当我在手机上使用android应用程序订购商品时,数据库中该商品的数量应该减少1您正在生产环境中使用此代码,人们可以购买,然后就可以使用了钱。。。使用不推荐使用的函数和凌乱的代码,可以肯定的是,这里也有SQL注入漏洞:-(thanx它工作得很好)
UPDATE `corro`.`food` 
SET `food`.`Quantityy` = (`food`.`Quantityy`- 1) 
WHERE `food`.`id` = $id AND `food`.`Quantityy` >= 0
UPDATE `corro`.`food` 
SET `food`.`Quantityy` = (`food`.`Quantityy`- 1) 
WHERE `food`.`id` = $id AND `food`.`Quantityy` >= 0
 $q=FALSE;  
 while($r = mysql_fetch_assoc($query1)) {

$output = $r['Quantityy'];
if($q===FALSE){
$q =  $output-1;
}else{
    $q--;
}
    //encode the returned data in JSON format
    echo $output;
    $query2=mysql_query("UPDATE food SET Quantityy ={$q}` where  `food`.`id` LIKE $output");
}