Hi,
Can understand why this isn't working. I'm basically populating an order items table using an order ref from the order header table, based on what is in the users cart.
I'm trying to execute an insert statement within a loop. But it's not inserting any data - am I missing anything?
dbConnect() simply creates a new PDO object.
Can understand why this isn't working. I'm basically populating an order items table using an order ref from the order header table, based on what is in the users cart.
I'm trying to execute an insert statement within a loop. But it's not inserting any data - am I missing anything?
dbConnect() simply creates a new PDO object.
PHP:
function createNewTelephoneOrderItems($SID, $orderRef) {
$db = $this->dbConnect();
$sqlCartItems = "SELECT * FROM cart INNER JOIN products ON cart.productID = products.pID WHERE sessionID = '".$SID."'";
$stmt2 = $db->prepare('INSERT INTO orders_items (orderRef, productID, prodTitle, prodPrice, prodQuantity, DMID) VALUES (:orderRef, :prodID, :prodTitle, :prodPrice, :prodQty, :DMID)');
foreach($db->query($sqlCartItems) as $row2) {
$pid = $row2['productID'];
$pname = $row2['pName'];
$pprice = $row2['pPrice'];
$pqty = $row2['quantity'];
$dmid = $row2['dmID'];
$stmt2->bindParam(':orderRef', $orderRef);
$stmt2->bindParam(':prodID', $pid);
$stmt2->bindParam(':prodTitle', $pname);
$stmt2->bindParam(':prodPrice', $pprice);
$stmt2->bindParam(':prodQty', $pqty);
$stmt2->bindParam(':DMID', $dmid);
$stmt2->execute();
}
}
Last edited: