Thread: Mysql error
View Single Post
Old 03-11-2009, 12:09 AM   #7 (permalink)
Tanax
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