Skip to content
Advertisement

Fetch array data from one table and insert into another table

I want to fetch array data from “orders” Table WHERE order_id =2 and insert into “inventory_log” Table. but my code is only inserting the last row

orders TABLE

JavaScript

I want this:

inventory_log TABLE

JavaScript

Find my code below:

JavaScript

Advertisement

Answer

It is only inserting one row because you are only posting 1 product_id and 1 quantity

your posted data in php now looks like :

JavaScript

If you want to send the entire list through a post you will need to use the array syntax in your input name .

Something like

JavaScript

in your php script this will result in a POST with an array value

JavaScript

which you can iterate with an foreach()

JavaScript

However. With your script you keep inserting ALL rows you already have. I dont know if this is just as try/example but i assume you just want to insert new rows. How its setup now you keep inserting all rows you already have ( even without deleting the old ones)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement