Help! Problem Inserting multiple rows...

Discussion in 'PHP' started by Ovim, Dec 28, 2007.

  1. #1
    I'm trying to build a basic "shopping cart" type thing. I've got a table "shopping cart" to which customers can put products. When they want to check out I have a form to which they insert name, address etc and that data is inserted into table "orders" into which also an order_id (auto_increment) is generated and shipping cost and total sum is calculated.
    In the same form also order details sel_item_id, sel_item_qty (hidden fields) are inserted to "order_details" table. mysql_insert_id is used to get the order_id from "orders" and also inserted to "order details".

    My problem is that I cant get more than one row inserted into "order details" . Even if there is more rows in "shopping_cart". I've tried some foreach and while statements without success.

    My PHP knowledge is very limited, so please help!

    these are my SELECT / INSERT queries:

    $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.")";
    } 
    PHP:
     
    Ovim, Dec 28, 2007 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to have

    mysql_query($insertSQLtwo);

    to actually execute the query.
     
    matthewrobertbell, Dec 28, 2007 IP