On Fri, 9 Feb 2001 13:46:45 -0800, [EMAIL PROTECTED]
([EMAIL PROTECTED]) wrote:
>Hi Everyone,
>    I have a big problem, that I bet could be solved pretty simply
>but I am
>new to mysql so its killing me and my database.
>
>    Ok heres the problem, suddenly out of no where when my php
>script tries
>to (or manually) do a insert it says:
>
>    ERROR 1062: Duplicate entry '127' for key 1
>
>
>Now why all of a sudden is this doing this at id 127?
>
>This is what my create table statement looks like if this is of any
>help to
>you:
>
>    CREATE TABLE custinfo (  id tinyint(4) DEFAULT '0' NOT NULL
>AUTO_INCREMENT, date date, name varchar(50), card varchar(22),
>exp_date
>varchar(7), authcode varchar(8), amount double(4,2), tax
>double(3,2), pnref
>varchar(16), address text, city tinytext, state varchar(
>3), zip varchar(15), country varchar(2), contact_first varchar(20),
>contact_last varchar(20), contact_phone varchar(20), contact_ema
>il tinytext, tickets tinyint(3), description varchar(50), PRIMARY
>KEY (id),
>UNIQUE id (id));

It's because you overflowed your tinyint in the id field.
By the way, a couple comments:
1) you don't need the last unique id (id), the primary key takes care

of that. what you're doing just makes an extra index where you only
need 1.

2) you might as well go for varchar(255) for all your varchars since
mysql will only use as much room as the data uses (not so for chars)
unless there's a reason you want your data to possibly get cut off.

3) you should always go for a regular int(11). performance-wise
you'll never notice a difference and it will keep you out of problems

like this one.

4) if you always go for not null with default values you will never
get php/perl problems with a field not being set. plus not nulls give

a small performance bonus.

any comments?

- Mark



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to