php - subtract value and update multiple rows -
i have cart , want update database right stock values. ordered products inserted table, can't update stoc table right values.
foreach($_post['produsc'] $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 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." prodid = '".$_post['codutc'][$row]."' , masura = '".$_post['masurac'][$row]."'"; mysqli_query($link, $up);
thx in advance
Comments
Post a Comment