减去值并更新多行

时间:2015-06-29 16:16:25

标签: php mysqli

我有一个购物车,我想用正确的库存值更新数据库。 我将订购的产品插入到表中,但是我无法使用正确的值更新stoc表。

foreach($_POST['produsC'] as $row=>$produsC) {

    $produsC=mysqli_real_escape_string($link,$produsC);
    $masuraC=mysqli_real_escape_string($link,($_POST['masuraC'][$row]));
    $codutC=mysqli_real_escape_string($link,($_POST['codutC'][$row]));
    $cantitateC=mysqli_real_escape_string($link,($_POST['cantitateC'][$row]));
    $pretC=mysqli_real_escape_string($link,($_POST['pretC'][$row]));
    $tokC=mysqli_real_escape_string($link,($_POST['tokC'][$row]));
    $row_data[] = "('$tokC' , '$codutC' , '$produsC' , '$masuraC' , '$cantitateC' , '$pretC' , NOW())";
}

if (!empty($row_data)) {
$sql = 'INSERT INTO orders (order_id, idd, produs, masura, cantitate, pret, data) VALUES '.implode

(',', $row_data);
$result = mysqli_query($link, $sql);
}

$up = "UPDATE stoc SET 
                    stoc = stoc - ".$cantitateC."
                WHERE prodid = '".$_POST['codutC'][$row]."' AND masura = '".$_POST['masuraC'][$row]."'";
                mysqli_query($link, $up);

提前谢谢

0 个答案:

没有答案