convert form input into integer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

convert form input into integer

Post by bytte »

I have an input textfield in my html form.
When submitted, the contents of that field should be made an integer.

(The input field allows for 11 characters, so I had to use bigInt in MySql.)

doing:

Code: Select all

(int)$_POST['number'];
creates an wrong integer.

What should I do? I think it has something to do with the 11 character length of the value inputted.
Everything below 11 characters is converted without any problem by the above method.
But as soon as I try to convert an 11 character value it fails.

Any idea?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP has a built-in upper limit to how long a basic integer can go. On most machines, it's 2,147,483,647. After that it'll wrap around to negative numbers.

Look into using GMP for larger integer math.
Post Reply