this is probably very easy, but the function below works on mysql 4 and 4.1, but not mysql 5. I am using this function via amfphp and want to make it so it works in both environments…
function insertDetails($OrderID,$Cart){
//inserts the order details into the many-many relationship table
//loop through the Cart array and insert the product and quantity ID's
$cardquery= mysql_query("SELECT cardnumbers.cardnumber FROM cardnumbers WHERE cardnumbers.idfield = 1");
$row=mysql_fetch_array($cardquery);
if(!mysql_error())
{
$cardnumber = $row[cardnumber];
for ($i=0; $i<sizeof($Cart); $i++)
{
$cardnumber += 1;
$optionCode = "GiftCard";
$optionCode .= $cardnumber;
$sql = sprintf("Insert into details(OrderID, ProductID, Quantity, orderoption1, orderoption2, orderoption3, orderedItemCode, designID, isGiftCard, shipperID, OrderTitle, OrderDescription, OrderPrice, OrderModelNumber, OrderGratuity, message, orderdate, shipperfname, shipperlname, fromname, toname, deliverymethod, isDownload, downloadID) values('".$OrderID."', '%s', '".$Cart[$i]['quantity']."', '".$Cart[$i]['option1']."', '".$Cart[$i]['option2']."', '".$Cart[$i]['option3']."', '".$optionCode."', '".$Cart[$i]['designID']."', '".$Cart[$i]['isGiftCard']."', '".$Cart[$i]['shipperID']."', '%s', '%s' , '".$Cart[$i]['price']."', '%s', '".$Cart[$i]['gratuity']."', '%s', NOW(), '%s', '%s', '%s', '%s', '".$Cart[$i]['deliverymethod']."', '".$Cart[$i]['isdownload']."', '%s')",
mysql_real_escape_string($Cart[$i]['productid']),
mysql_real_escape_string($Cart[$i]['title']),
mysql_real_escape_string($Cart[$i]['desc']),
mysql_real_escape_string($Cart[$i]['modelnumber']),
mysql_real_escape_string($Cart[$i]['textmessage']),
mysql_real_escape_string($Cart[$i]['shipperfname']),
mysql_real_escape_string($Cart[$i]['shipperlname']),
mysql_real_escape_string($Cart[$i]['fromname']),
mysql_real_escape_string($Cart[$i]['toname']),
mysql_real_escape_string($Cart[$i]['downloadID']));
mysql_query($sql);
mysql_query("UPDATE products SET quantity = quantity - '".$Cart[$i]['quantity']."' WHERE products.ProductID = '".$Cart[$i]['productid']."'");
}
mysql_query("Replace into cardnumbers(idfield, cardnumber) values(1, '".$cardnumber."')");
} else {
return "error";
}
//if no errors, return the OrderID
if(!mysql_error()) return $OrderID;
//else return error
else return "error";
}