Web Hosting Talk







View Full Version : Get this error


SupaJ
10-22-2005, 04:00 PM
Error Diagnostic Information

ODBC Error Code = 23000 (Integrity constraint violation)

[MySQL][ODBC 3.51 Driver][mysqld-4.0.16]Duplicate entry '32767' for key 1

SQL = "INSERT INTO hitcounter (hdate, ipaddy) VALUES ('22-Oct-05' , '86.131.185.169')"

Data Source = "M9523_FM_REHAB_SITE"

When I go to my site: www.fmrehab.com

Can anybody help? It'd be very much appreciated.

jgothier
10-22-2005, 04:50 PM
It looks to me like you have a field in your database setup to not allow duplicate entries. Look at the hitcounter table and check the 2 fields hdate, ipaddy and make sure that you don't have one set as a Primary key, and also make sure you have it allow duplicates on both fields as well. Unless you don't want it to allow duplicates and you want that record to update when the same Ip address returns. If that is the case, then you need to query the database to see if that IP already exists and if it does don't do the insert do an update instead.

Hope this helps. If it dosent, post some code and I will look at it for you.

Justin

gogocode
10-23-2005, 04:02 AM
Post the structure of the hitcounter table.

maro25
10-23-2005, 10:16 AM
well we need to know what is the structure of the hitcounter table... Most importantly we need to know what is your primary key and how is it structured

FalseDawn
10-23-2005, 12:20 PM
Looks like it has been fixed, but in any case, the fact that 32767 is the largest value for a signed smallint should have made the solution pretty obvious - change the key1 datatype from smallint to int

maro25
10-24-2005, 01:25 AM
aha that was pretty clever to notice that largest smallint value! I didn't take notice

innova
10-24-2005, 03:44 PM
Make it unsigned as well. No need to have negative values in an autoincrement field.

Rich2k
10-24-2005, 05:32 PM
I can't tell you how many times I made that error when I first started programming with databases. Always use INT(11) these days for id fields.

innova
10-24-2005, 06:00 PM
Rich,

INT(11) and INT are the same thing - the 11 is the 'display' width which does not affect how many characters can be stored.

Hell you can do INT(1) and still store an enormous number.