hi there, I am developer with 4 years of experience in PHP and NodeJs.
Your database should have two different tables.
e.g:
tbl_orders:
here your orders will be placed like. id, user_id, total_amount, order_date
tbl_order_detail:
here you will insert your cart items.
First you have to insert into tbl_orders and then get the last inserted id and insert that id and shopping cart values in tbl_order_details.
You will tables structures like:
TBL_ORDERS:
id | user_id | total_amount | datetime | discount | coupon |
TBL_ORDER_DETAILS:
id | order_id (id of tbl_order) | product_id (items in cart) | price (price of single item) | quantity (quantity of single item)
If you wish to store these in single table :
you must generate RANDOM ID before inserting in order table and it should passed with all records so it will same for all records and you must fetch it using this random id.
Hope that helps. If you want to discuss more. Ping me.
Thanks
Regards,
Taimur Tariq