PHP - can't add row past a certain id number

software development

#1

Hi there,
got a prob which i hope someone can help me with.
I’ve got a table which has about 70 rows in. The rows’ ids start at 1, have a large gap in the middle, then range up to 127. If I try to add a new row with an autoindexed new id, I get the following MySQL error: duplicate entry ‘127’ for key 1.
If I add a new row with a lower id, e.g. 6, there are no issues - it works fine. If I delete row 127, or give it a lower number, I can then add a new row as normal, but then the error happens again for all subsequent rows.

Everything was working fine with the page that adds new rows until it got to 127. Is this some kind of magic number I don’t know about?


#2

Sounds like you are using the ‘TINYINT’ integer type for the id, whose range is signed -128…127

Here is a like to the MySQL data types and their sizes: MySQL Manual - 12.1 Numeric types

Please use phpMyAdmin and on the “structure” page for that table, check what it says the “Type” and “Attributes” are for that field. Also, there is a section called “Indexes” and if there are any indexes with a “Field” matching your id field, check on the “Type” and possibly “Size” (a number that would appear next to the field name).

If the structure looks OK, you’d probably want to check your code, perhaps there is a programmer error.

:cool: Perl / MySQL / HTML CSS


#3

You were spot on - changed it from tinyint to smallint, and everything’s working fine now. Thanks very much! :slight_smile: