当销售表数量增加时,可用数量列会自动减少

时间:2016-03-03 12:24:24

标签: php mysql mysqli

$sql = "INSERT INTO stock (Date, Description, Product_Code, DEO, Cartons, Items, Quantity, Sent_To) VALUES ('$date','$description', '$productcode','$deo', '$cartons', '$items', '$quantity', '$sent_to')";
    //$sql1 = "SELECT * FROM stockcount WHERE Product_Code = '".$productCode."';
    //$sql1 = mysqli_query("UPDATE stockcount SET Quantity='" . Quantity-$quantity . "' WHERE Product_Code='$productcode'");


    if ($conn->query($sql)===TRUE) {

        header("Location:sendorder.php");

    }
    else {

        echo "Error is " .$sql."<br>". $conn->error;
    }

$ sql插入日期,描述,product_code,deo,纸箱,物品,数量并发送到股票表。 product_code是stock表中的外键,它通过下拉列表插入。我想通过产品代码找到stockcout表中的产品,并通过$ sql插入的数量减少其数量。请帮我生成一个可以通过库存计数表中的product_code更新数量的查询。我已经尝试了一些我评论过的查询,请检查一下。 You can see both the stock and stockcount table here。如果你能帮助我,我会很高兴的。提前致谢

1 个答案:

答案 0 :(得分:0)

应该使用mysql触发器。在成功插入行时,应该激活触发器,你应该有逻辑来做你想做的任何事情。

触发参考:http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html