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

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.