Ok, I’m working on a php college project, and I have to let students register, submit their details- firstname, surname, phone number, id number, etc.
At first I used int for id number but I’m not going to do any math with it so I changed it to varchar, however after this change, all the examples I submitted still comes out with the maximum int value “2147483647” when I specified it to be varchar, why does this happen and how can I fix it.
If it helps the collation of the table fields are all latin1_swedish_ci.
I’m not a MySQL expert, so if there is any other info you need to get to the bottom of this problem just ask.
Edit: I also changed the fields’ value back to bigint and it still throws 2147483647 in the table, even though I entered 8888888888888(13 characters), so with varchar or bigint i still get 2147483647, what am I doing wrong?
Update:I got the following error from phpmyadmin when trying to change the max value for the field.
SQL query:
ALTER TABLE `student` CHANGE `idno` `idno` BIGINT( 99999999999999 ) NOT NULL
MySQL said:
#1439 - Display width out of range for column 'idno' (max = 4294967295)
Update: taking out intval() fixed this issue
$id_number=intval($_POST['id_number']);
$id_number=($_POST['id_number']);
Don’t use
varcharas ID unless you really need to use letters in the ID (PK?) field. It’s faster to use integers. Maybe the PHP script is trying to change the DB’svarcharto an integer so change the ID back toint.Do you really need
bigint? Unsignedintmay be more than enough.http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
Update: If you need to make sure the value is an integer you should check it’s datatype.
If the value comes from DB (column which’s datatype is integer) everything should be OK but it never hurts to check…