I have a script (listed below) which is intended to enter items into a database based on the results of a query. I need it to enter several rows of data based on what has been included in a shopping cart. In any event, I have tried to use a 'while' function, but am only getting 1 row returned. However, there are 5 lines of data in the source table... Help!
Code: Select all
<?php
//Retrieve the item details of the cart
$orderDetailQuery="SELECT * FROM cart INNER JOIN pieces ON cart.piecenum=pieces.piecenum WHERE cookieID='" . GetCartId() . "'";
$result = mysql_query ($orderDetailQuery) or die("ERROR, ERROR!".mysql_error());
$numRows = mysql_num_rows($result);
echo $numRows;
//Go through each of the items in the cart
while ($row=@mysql_fetch_array($result))
{
$piecenum = $row['piecenum'];
$price = $row['price'];
$description = $row['description'];
$qty = $row['qty'];
$randomOrderID= $_SESSION['randomOrderID'];
$insertquery="INSERT INTO orderdetails(randomOrderID, itemNum, itemDesc, quantity, price) VALUES('$randomOrderID','$piecenum','$description','$qty', '$price')";
$result = mysql_query ($insertquery) or die("ERROR, ERROR!".mysql_error());
}
?>