TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-10-2009, 02:14 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Mysql error

Hi!

What's causing this error? :S

Quote:
INSERT INTO `images` ( `image_id` , `image_productid` , `image_src` , `image_front` )
VALUES (
NULL , '', 'includes/images/palmyra10sl.jpg', ''
)

#1062 - Duplicate entry '127' for key 1
I have 127 entries in that table. I'm adding another entry, manually via phpmyadmin. The image_id is set to primary key. When I add the entry, I've tried leaving image_id blank(meaning it SHOULD add it to the next available key), and also tried putting it to 128, but it doesn't work either :S:S
__________________
Tanax is offline  
Reply With Quote
Old 03-10-2009, 09:59 PM   #2 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

What field type and size is your primary key?
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/
etoolbox is offline  
Reply With Quote
Old 03-10-2009, 10:45 PM   #3 (permalink)
The Wanderer
 
Join Date: Mar 2009
Location: Colorado
Posts: 6
Thanks: 0
codeguy is on a distinguished road
Default

Since you seem to expect image_id to increment from submitting a null value, I assume auto_increment was specified for image_id.

my guess is the same as where i think etoolbox was going. Use a larger int (guessing image_id is tinyint) small int/medium int/int (i'd prolly recommend Int).
codeguy is offline  
Reply With Quote
Old 03-10-2009, 10:45 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Without knowing the type like etoolbox said it's kind of hard.
If it is a primary key, it is not safe to leave it a null, so the record is not created. That could be the reason.
If the image_id is set to auto_increment, you don't need to make an explicit insert with that field, something like this would work:

Code:
INSERT INTO images(image_productid, image_src, image_front)
VALUES ('', 'includes/images/palmyra10sl.jpg', '')
But I might be wrong, I just finished a project working with Access SQL so that might not be right. If that is not right try to save the default value like this:

Code:
INSERT INTO images(image_id, image_productid, image_src, image_front)
VALUES (DEFAULT, '', 'includes/images/palmyra10sl.jpg', '')
I am no expert in mysql though, this is just speculations, but maybe it would help.
tony is offline  
Reply With Quote
Old 03-10-2009, 10:58 PM   #5 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

My guess is it's a tinyint with a max integer value of 127. You cannot insert a value > 127 into this field. What MySQL "helpfully" does is to try to make it the highest value if it's not specified and because that key already exists you get a "duplicate entry" error when in fact that's not the real error, it's that you have an overflow on the PK.
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/
etoolbox is offline  
Reply With Quote
The Following User Says Thank You to etoolbox For This Useful Post:
nefus (03-11-2009)
Old 03-10-2009, 11:03 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by codeguy View Post
Use a larger int (guessing image_id is tinyint) small int/medium int/int (i'd prolly recommend Int).
I'd also go with the unsigned tinyiny column theory. The tinyint (when unsigned) has a max value of 127. Trying to insert a new auto_incremented value higher than that will indeed raise the "Duplicate entry '127' for key 1".
Salathe is offline  
Reply With Quote
Old 03-11-2009, 12:09 AM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Wow, alot of replies

Quote:
Originally Posted by etoolbox View Post
What field type and size is your primary key?
image_id tinyint(3)

Quote:
Originally Posted by codeguy View Post
Since you seem to expect image_id to increment from submitting a null value, I assume auto_increment was specified for image_id.

my guess is the same as where i think etoolbox was going. Use a larger int (guessing image_id is tinyint) small int/medium int/int (i'd prolly recommend Int).
Indeed you are correct to assume that. I have it auto_increment.
You're good at guessing

Thanks! I'll try changing it

Quote:
Originally Posted by tony View Post
Without knowing the type like etoolbox said it's kind of hard.
If it is a primary key, it is not safe to leave it a null, so the record is not created. That could be the reason.
If the image_id is set to auto_increment, you don't need to make an explicit insert with that field, something like this would work:

Code:
INSERT INTO images(image_productid, image_src, image_front)
VALUES ('', 'includes/images/palmyra10sl.jpg', '')
But I might be wrong, I just finished a project working with Access SQL so that might not be right. If that is not right try to save the default value like this:

Code:
INSERT INTO images(image_id, image_productid, image_src, image_front)
VALUES (DEFAULT, '', 'includes/images/palmyra10sl.jpg', '')
I am no expert in mysql though, this is just speculations, but maybe it would help.
Yea, I think I already know now what the problem is based on what the others said

Quote:
Originally Posted by etoolbox View Post
My guess is it's a tinyint with a max integer value of 127. You cannot insert a value > 127 into this field. What MySQL "helpfully" does is to try to make it the highest value if it's not specified and because that key already exists you get a "duplicate entry" error when in fact that's not the real error, it's that you have an overflow on the PK.
Thank you for the information, I'll be sure to remember it next time

Quote:
Originally Posted by Salathe View Post
I'd also go with the unsigned tinyiny column theory. The tinyint (when unsigned) has a max value of 127. Trying to insert a new auto_incremented value higher than that will indeed raise the "Duplicate entry '127' for key 1".
Thanks alot! I'll edit this error asap
__________________
Tanax is offline  
Reply With Quote
Old 03-11-2009, 05:05 AM   #8 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Great, Let us know how you fix it then ;)
tony is offline  
Reply With Quote
Old 03-11-2009, 05:35 PM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by tony View Post
Great, Let us know how you fix it then ;)
I just changed the column to int(11) unsigned, and it's working great now
__________________
Tanax is offline  
Reply With Quote
Old 03-11-2009, 09:03 PM   #10 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Good! I tend to forget about the sizes of the numeric fields too.
tony is offline  
Reply With Quote
Old 03-11-2009, 10:54 PM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I certainly did that now xDD But luckily talkphp exists
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Error with Pagination Orc MySQL & Databases 29 11-21-2011 10:58 AM
MySQL Server error #2003(HY000): Can't connect to MySQL Server on 'localhost'(10061) Yoosha MySQL & Databases 3 06-15-2009 02:45 PM
Error in Mysql zxt3st Absolute Beginners 4 09-28-2008 09:24 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM


All times are GMT. The time now is 12:42 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design