OriginalSunny Posted March 7, 2006 Share Posted March 7, 2006 Hi, i am getting the following error when inserting data into one of my tables using php. From what i can see the error is telling me i am inserting the same data twice for a column.[i]sql_item: Duplicate entry '0' for key 1[/i]I can insert data into the table once, however when run again this error comes up. If i delete the data in the table and start again, the same thing happens. The first time it will enter the data in the table and the next time the error comes up. As it is a shopping basket i need to be able to enter the data in the table more than once. Here is the code related to the problem: $sql_ord = "INSERT INTO Order_Item (orderID,modelnum, quantity,price) VALUES ($orderID, {$items_new[$i]['modelnum']}, {$items_new[$i]['quantity']}, {$items_new[$i]['price']})"; $result = mysql_query($sql_ord,$connect) or die("sql_ord: ".mysql_error($connect));The table it is inserting data has the following columns:stockID - Primary Key (int (5))orderID - int (6)quantity - int (6)price - decimal (9,2)From what i remember i don't think any of the columns were auto_increment.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/4327-error-in-code/ Share on other sites More sharing options...
Toni_montana Posted March 7, 2006 Share Posted March 7, 2006 Hey there,$orderID seems to have a certain key to it. (unique, or primary) that doesn't allow identical values. This is good. You need one of these in every DB.it's probably wise to use auto_increment because, when you insert a new one, the $orderID value is still at '0'.This will cause your next insert to malfunction, because there is already a '0'.So either change it to auto_increment or use proper orderID's. That are non-identical.Good luckRogier Quote Link to comment https://forums.phpfreaks.com/topic/4327-error-in-code/#findComment-15043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.