Odie Odie - 1 year ago 76
MySQL Question

If a column has a value add via update

I have a column

which has an initial value of 0. When I input some number on my input field

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

I want to update my
to my

Here is my initial code:

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

Here's an example:

| 0 |

When I input 10, this should be the result:

| 10 |

and if I input 25, it should add with the 10 in the

| 35 |

How do I do this?

Answer Source
UPDATE stock_transfer SET stocks_transferred = stocks_transferred + $qtyBuy WHERE transfer_product_id = 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download