更新mysql中的开始和结束值

时间:2017-04-05 21:54:20

标签: php mysql

table structure

如果用户输入现有产品,我想更新开头和结尾的值。我的更新查询中有什么问题吗?谢谢!

if(isset($_POST['status2'])){

          $rowValues = explode("//", $_POST['status2']);

          $orderId = $rowValues[0];

          $dateReceivedNo = $rowValues[1];

          $receivedDate = $_POST[$dateReceivedNo];



          mysqli_query(connect(), "UPDATE `order` SET `status` = 'RECEIVED' WHERE `order_id` = '$orderId'");

          $product = mysqli_query(connect(), "SELECT * FROM `order` WHERE `order_id` = '$orderId' AND branch_name = '$name' ");
          $product2 = mysqli_fetch_assoc($product);

          $cate = $product2['cat_name'];
          $item = $product2['item_name'];
          $prodName = $product2['product_name'];
          $quantity = $product2['quantity'];

          mysqli_query(connect(), "INSERT INTO `logs`(`log_id`, `branch_name`, `activity`, `date`) VALUES ('', '$name', 'RECEIVED ITEM ".$prodName. " ". $quantity ."', now())");

          $count = mysqli_query(connect(), "SELECT count(invbranch_id) AS 'countItems' FROM `inventorybranch` WHERE `cat_name` = '$cate' AND `item_name` = '$item' AND `product_name` = '$prodName'");
          $count2 = mysqli_fetch_assoc($count);

          if($count2['countItems'] > 0){
            mysqli_query(connect(), "UPDATE `inventorybranch` SET `beginning` = (`beginning` + '$quantity'), `date` = NOW() WHERE `cat_name` = '$cate' AND `item_name` = '$item' AND `product_name` = '$prodName' AND `status` = 'DELIVERED'");

             mysqli_query(connect(), "UPDATE `inventorybranch` SET `quantity` = (`quantity` + '$quantity'), `date` = NOW() WHERE `cat_name` = '$cate' AND `item_name` = '$item' AND `product_name` = '$prodName' AND `status` = 'DELIVERED'");
          }

          else{
            mysqli_query(connect(), "INSERT INTO `inventorybranch` VALUES ('','','$cate','','$item','','$prodName','$name','$quantity','$quantity','','','', now())");
          }

          mysqli_query(connect(), "UPDATE `inventoryho` SET quantity = (quantity-'$quantity') WHERE cat_name = '$cate' AND item_name = '$item' AND product_name = '$prodName'"); 
          mysqli_query(connect(), "UPDATE `order` SET `date_receive` = now() WHERE `order_id` = '$orderId'");


}

0 个答案:

没有答案