I've edited this because I've made some progress, but still need help.
I'm trying to insert into a table "order_details" data fetched from another table ("shoping_cart") and I also need to insert an order_id which I'm getting from previous insert with "mysql_insert_id". I'm getting the data from "shopping_cart" with session_id and it can be one or more rows.
The problem is that my query only inserts one row even if there should be more. I've tried for and while (not sure if I did them right though) loops. The only result was that the one inserted row was the last one of selected (from "shopping_cart") when it earlier was the first one.
This is my query now:
$myResult1ID = mysql_insert_id();
$query = "SELECT sel_item_id, sel_item_qty FROM shopping_cart WHERE session_id = '$sessionnbr'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$sel_item_qty = $row['sel_item_qty'];
$sel_item_id = $row['sel_item_id'];
$insertSQLtwo = "INSERT INTO order_details(order_id, sel_item_id, sel_item_qty)
VALUES (".$myResult1ID.", ".$sel_item_id.", ".$sel_item_qty.")";
}
before edit : I dont know much of php, but i started making this webstore (just for fun, not for real life) using Dreamweavers recordsets and data insertion form wizards and such.
Soon I realized that I couldn't do everything using wizards and now I've got a problem.
I've got a "shopping cart table" to which customers' selected products go.
Each row in that table hold id, session_id, item_id and item_qty.
When customers check out they fill a form where they enter their address etc. This forms data is inserted to "orders" table which holds order_id, customer info, order total sum etc. The details of items in every order are stored in "order_details" table which holds id, order_id, item_id, item_qty.
So basically every order creates one row to "orders" table and one or several rows to "order_details" table.
I first made the checkout form with dreamweaver and it inserts into "orders" (this works) then I modified (according to some tutorial )the form so that it should also insert into "order_details" (this works partly).
After the first part of insert into (to orders) I used mysql_insert_id to retrieve the order_id and insert it to order_details (this works, for every order I get one row to "order_details" with the correct order_id and NULLs to item_id and item_qty)
Here is my problem. I dont know how to make the insert into query so that it inserts one or multiple rows (of item_ids and qtys) to order_details and inserts the same order_id to all of these rows.
I've managed to get the required info from "shopping cart" with this query.
$query = "SELECT session_id, sel_item_id, sel_item_qty FROM shopping_cart WHERE session_id = '$sessionnbr'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$sel_item_qty = $row['sel_item_qty'];
$sel_item_id = $row['sel_item_id'];
}
How can I insert this data to my "order details"?
Please Help!