Hi. In the script processing a form I included conditional statement:
if((is_int($tireqty)==FALSE)||(is_int($oilqty)==FALSE)||(is_int($sparkqty)==FALSE)){
echo '<h1><b><font color=red>Wrong data inputted! Quantities have to be integers! </font></b></h1>';
exit;
}
where $tireqty, $oilqty and $soarkqty are input variables. However is_int() returns FALSE every time, because whatever data is inputted using the form, it is always interpreted as string type, which I checked using gettype() function. Why is that? Please help.
Form input variable type interpretation problem
Moderator: General Moderators
-
Hairy Potter
- Forum Newbie
- Posts: 2
- Joined: Thu Oct 30, 2008 1:24 pm
Re: Form input variable type interpretation problem
Data coming from outside (like through $_GET or $_POST) will always be a string.
The string equivalent to is_int is ctype_digit: checks if a string has only digits (no letters, not even a negative sign or decimal point). If you want to know if something is a number (could be an integer or a real) then use is_numeric.
The string equivalent to is_int is ctype_digit: checks if a string has only digits (no letters, not even a negative sign or decimal point). If you want to know if something is a number (could be an integer or a real) then use is_numeric.
-
Hairy Potter
- Forum Newbie
- Posts: 2
- Joined: Thu Oct 30, 2008 1:24 pm
Re: Form input variable type interpretation problem
Thanks a lot. ctype_digit is the function I needed.