title: SQL insert multiple rows, foreach
body: <p>I'm trying to <code>insert</code> multiple <code>rows</code> into my DB dependening how many iterations of an array are returned.</p>
  
  <p>The insert is working, but doenst insert more than 1 row, regardless of whats in the array.</p>
  
  <pre><code>function createOrder(){
  
    $CustomerID = $_SESSION['CustomerID'];
    $BasketID = $_SESSION['BasketID'];
  
    // create a new entry with an OrderID
    $orders = new Basket;
    $orders-&gt;storeFormValues( $_POST );
    // Collect the OrderID returned from insertOrder(); and insert into 'Orders'
    $OrderID = $orders-&gt;insertOrder($CustomerID);
  
    // Populate OrderDetails with items in users Basket.
    $data = Basket::getBasket($BasketID);
    $results['basket'] = $data['results'];
  
    // Insert the order details into the orderDetails DB.
    $orders-&gt;insertOrderDetails($OrderID, $BasketID, $CustomerID, $results); 
  };
  </code></pre>
  
  <p>and the loop:</p>
  
  <pre><code>public static function insertOrderDetails($OrderID, $BasketID, $CustomerID, $results){
     $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  
      // for each row insert into the DB
      foreach ( $results['basket'] as $row ) {
        $sql = "INSERT INTO OrderProducts (OrderID, ProductName, Price, Quantity) 
                VALUES (:OrderID, :ProductName, :Price, :Quantity)";
  
        $st = $conn-&gt;prepare( $sql );
        $st-&gt;bindValue( ":OrderID", $OrderID, PDO::PARAM_INT );
        $st-&gt;bindValue( ":ProductName", $row-&gt;ProductName, PDO::PARAM_STR );
        $st-&gt;bindValue( ":Price", $row-&gt;Price, PDO::PARAM_INT );
        $st-&gt;bindValue( ":Quantity", $row-&gt;Quantity, PDO::PARAM_STR );
        $st-&gt;execute();
  
     }
      $conn = null;
  }
  </code></pre>
  
  <p>And the array, <code>$results</code> looks like;</p>
  
  <pre><code>array(1) {
    ["basket"]=&gt;
    array(2) {
      [0]=&gt;
      object(Basket)#3 (10) {
        ["OrderID"]=&gt;
        NULL
        ["CustomerID"]=&gt;
        NULL
        ["OrderItemID"]=&gt;
        NULL
        ["ProductID"]=&gt;
        string(1) "9"
        ["Quantity"]=&gt;
        string(1) "4"
        ["ProductName"]=&gt;
        string(12) "Cheese Bagel"
        ["Price"]=&gt;
        string(1) "1"
        ["NameType"]=&gt;
        string(5) "Bagel"
        ["BasketProductID"]=&gt;
        string(2) "25"
        ["BasketID"]=&gt;
        string(1) "3"
      }
      [1]=&gt;
      object(Basket)#5 (10) {
        ["OrderID"]=&gt;
        NULL
        ["CustomerID"]=&gt;
        NULL
        ["OrderItemID"]=&gt;
        NULL
        ["ProductID"]=&gt;
        string(1) "2"
        ["Quantity"]=&gt;
        string(1) "1"
        ["ProductName"]=&gt;
        string(15) "The British BLT"
        ["Price"]=&gt;
        string(1) "3"
        ["NameType"]=&gt;
        string(5) "Bagel"
        ["BasketProductID"]=&gt;
        string(2) "26"
        ["BasketID"]=&gt;
        string(1) "3"
      }
    }
  }
  </code></pre>
  
  <p>Any suggestions greatly apprecaited!</p>