Jump to content


This topic is now archived and is closed to further replies.


Error in code?

Recommended Posts

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
quantity,price) VALUES
$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.

Share this post

Link to post
Share on other sites
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 luck


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.