chet139 Posted February 27, 2008 Share Posted February 27, 2008 Hi All, I have the following code which does what I want it to do: To take specific rows from table "cart" and put into table called "orderline": //Get all items from cart for that order and put into variables. $sql2 = "select * from furniture.cart where ordId = $orderId"; $result2 = @mysql_query($sql2);//runs query while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { $cproductId = $row['productId']; $cordId = $row['ordId']; $cqty = $row['qty']; //take variable values and put into another table called orderline $sql3="INSERT INTO furniture.orderline (ordId, productId, ordQuantity) VALUES ($cordId, $cproductId, $cqty)"; if (!mysql_query($sql3,$con)) { die('Error: ' . mysql_error()); } echo $sql3; } ECHOING the query returns this INSERT INTO furniture.orderline (ordId, productId, ordQuantity) VALUES (59, 1, 1)INSERT INTO furniture.orderline (ordId, productId, ordQuantity) VALUES (59, 2, 1) - Which is the SQL statement I expected.... however in addition to this I recieve the following error: Error: Duplicate entry '59-2' for key 1 . But the records that need to be added are added. So with this in mind I removed if (!mysql_query($sql3,$con)) { die('Error: ' . mysql_error()); } from the code above. But when I do this only (59, 2, 1)are inserted and not (59, 1, 1). I thought by removing the small if clause would solve my problems as it done what I required..... If this is not clear please ask...I am quite new to this Thanks Link to comment https://forums.phpfreaks.com/topic/93330-inserting-possible-multiple-table-rows-from-one-to-another-table/ Share on other sites More sharing options...
chet139 Posted February 27, 2008 Author Share Posted February 27, 2008 [sOLVED] I left another bit of code which was effecting this! Link to comment https://forums.phpfreaks.com/topic/93330-inserting-possible-multiple-table-rows-from-one-to-another-table/#findComment-478048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.