c_shelswell Posted May 20, 2008 Share Posted May 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
Xurion Posted May 20, 2008 Share Posted May 20, 2008 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' Quote Link to comment Share on other sites More sharing options...
KenDRhyD Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 20, 2008 Share Posted May 20, 2008 ... change the definition of the auto-increment field so it accepts numbers bigger than 127 http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html smallint should work. Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted May 20, 2008 Author Share Posted May 20, 2008 Andy - thank you - i now feel like a total idiot that was exactly my problem, had it set to tinyint. Thanks very much Quote Link to comment Share on other sites More sharing options...
fenway Posted May 20, 2008 Share Posted May 20, 2008 I prefer INT UNSIGNED for my UIDs. Quote Link to comment 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.