Jump to content

[SOLVED] Keep getting an error in insert - Duplicate entry '127' for key 1!!!


c_shelswell

Recommended Posts

I have no idea why i keep getting this error no matter wether i'm online or just using the same database locally. I've got a pretty basic table with 7 columns. I have a primary key which is 'ID' set to auto_increment however for some very very strange reason whenever i try to insert data i get 'Duplicate entry '127' for key 1'

 

my query is

insert into photos values (NULL, '1211275966', 'ghj', 'thumbMay 08 Uretiti and Horses 002.JPG', 'May 08 Uretiti and Horses 002.JPG','More Horse', '8')

 

So i was under the impression it should add the next number in the chain... 128???

 

Any help would be great cheers

Can you make your mysql query a little bit more obvious? At the moment if you added a column in your database somewhere in the middle, it would break this code, as the information would be input into the wrong columns.

 

Use either:

 

INSERT INTO photos (columna, columnb, columnc) VALUES ('valuea', 'valueb', 'valuec')

 

or

 

INSERT INTO photos SET columna='valuea', columnb='valueb', columnc='valuec'

Without knowing the specific table definition, it is difficult to determine the nature of your problem.

 

As Xurian noted, you should expressly identify the columns being inserted for  number of reasons. I suspect you have an auto_increment primary key, which you would not normally specify when INSERTing -- if you do not name the columns then they are implied in order defined.

Archived

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

×
×
  • Create New...

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.