如果列具有通过更新添加的值

时间:2016-11-27 15:27:57

标签: php mysql

我有一个列transfer_quantity,其初始值为0.当我在输入字段输入一些数字时

<input type="number" name="qtyBuy">

我想将transfer_quantity更新为qtyBuy值。

这是我的初始代码:

UPDATE stock_transfer SET stocks_transferred = $qtyBuy WHERE transfer_product_id = 1 ON DUPLICATE KEY UPDATE stocks_transferred = stocks_transferred + $qtyBuy;

以下是一个例子:

|stocks_transferred|
|       0          | 

当我输入10时,这应该是结果:

|stocks_transferred|
|       10          | 

如果我输入25,则应在

中添加10
|stocks_transferred|
|       35         | 

我该怎么做?

1 个答案:

答案 0 :(得分:1)

UPDATE stock_transfer SET stocks_transferred = stocks_transferred + $qtyBuy WHERE transfer_product_id = 1