Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php/ mysql record number issue

Status
Not open for further replies.

ckennerdale

Programmer
Dec 23, 2000
158
GB
I have set up a database with an add.php file to insert records.

Hewre is the schema of the database

CREATE table whatsnew (
id tinyint(8) NOT NULL auto_increment,
date timestamp(14),
text text NOT NULL,
title tinytext NOT NULL,
PRIMARY KEY (id),
UNIQUE id (id)
);


The problem is thaty wehn I reach 127 records I cannot add any more and get a mesAGE SIMILAR TO-

"duplicate entry "127" for key 1 "

if I clear the database then everything is back to normal

any ideas?

Caspar Kennerdale
Senior Media Developer
 
The problem is your specification for the id column type. You picked "tinyint" which, without regard to the size inputted in the parentheses, is restricted to -128 to 127 in signed mode (default) or 0 to 255 in unsigned mode (the word "unsigned" must follow the column type). With the 8 in there, I assume you're looking for the latter (8 bits = 256 possibilities), so simply change your layout to:

CREATE table whatsnew (
id tinyint unsigned NOT NULL auto_increment,
date timestamp(14),
text text NOT NULL,
title tinytext NOT NULL,
PRIMARY KEY (id),
UNIQUE id (id)
);

You may also want to change the "text" column name. Usually a good idea to avoid MySQL terms in naming columns. And I don't think the redundancy of UNIQUE id (id) is necessary either. Just UNIQUE(id) will work.

Take care,

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top