Forum Moderators: coopster

Message Too Old, No Replies

Insert Value in MySQL

         

woldie

2:02 pm on Oct 10, 2004 (gmt 0)

10+ Year Member



Hi,

I've got a small problem. I'm trying to insert some values into a DB. Now I'm using phpMyAdmin, which I haven't used for a while. But what I've done is echoed out the insert statement and copied into phpMyAdmin and I get this error:

Duplicate entry '0' for key 1

What does this mean?

Thanks.

mincklerstraat

2:09 pm on Oct 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like an auto-increment field (like an ID). This means that each time a record is added, this field automatically gets numbered by itself (you don't provide the number). Try doing the same thing over again without the info for that field and see if your SQL works.

Could also be a unique field, though less likely; in that case, you just have to pick a value that's not already in that field.

woldie

2:26 pm on Oct 10, 2004 (gmt 0)

10+ Year Member



Thanks mincklerstraat.

I've had a look at the table structure in phpMyAdmin, see below,

fieldname int(5) UNSIGNED No 0 Change Drop Primary Index Unique Fulltext

With 'Fulltext' not shown as a link.

Looks like its not a primary key field type, I think this is why its not inserting into the DB.

Woldie

ergophobe

3:15 pm on Oct 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't really know PHP MyAdmin, but I think that this


fieldname int(5) UNSIGNED No 0 Change Drop Primary Index Unique Fulltext

are all those little icons in the "Action" section. It doesn't really mean anything unless you know which way they are set. In other words, phpMyAdmin shows those options for every field, whether it's a primary key or not, but I think the color of the icon changes. It certainly makes no sense that a unique indexed integer field would have a fulltext index (it's only allowed on char, varchar and text columns).

What you probably have is a field that is set to "unique" and you are trying to insert the same value over again. You probably do not want to insert that value again and it's a problem in your script logic. It looks, for example, that some value is not getting passed and you're always trying to set that unique columnto zero, which creates a problem.

Assuming you do want to have duplicate values in that field, you'll need to change the table structure. To find out what the tables look like, in your phpMyAdmin SQL window, try entering the following

DESCRIBE mytable;

then

SHOW KEYS FROM mytable;

That will tell you all about the structure of the fields in question and we can take it from there.