I have below mentioned Issue.
I am developing inventory system using php.
According to that i have to add invoiced items to table.
Dynamically generated text box used to collect received item details.
I have current_stock table and it contain Item-name and qty columns.
Item-name is primary key field.
item which i am going to insert if already exist quantity should be updated with new value.
if it is not exist should be inserted as a new row.
This is must be done in loop because i use dynamically genarated text box and data collect using $item[] and $qty[] arrays.
I am try to use several ways to solve this issue unable to execute in for loop but not yet success.
please help me.........
for multiple query excution you have to use
mysqli_multi_query()
like this :
mysqli_multi_query("INSERT INTO TABLE SET Field='Value',FieldB='ValueB';
UPDATE TABLE SET Field='Value',FieldB='ValueB' WHERE FIELDID='VALUEID';")
i hope this will work.have fun.
you can try this :
INSERT INTO table (id, item_name, qty) VALUES(1, "A", 19) ON DUPLICATE KEY UPDATE
item_name="A"
If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row.