I am trying to validate a zip code from a form using the following code.
if (!is_int($zipcode) || $zipcode == ""){ $error[] = "Zip Code"; //error array }
I don't know why this won't work? Can someone please help.
Thanks
you must specify the arryfield: $error[0] = "Zip Code";
Thanks, but my problem is not the array. The array will be created whether I give it a key or not. My problem is that my "OR" statement will not return true. I want to make sure that the visitor filled anything in the form field ($zipcode ==""), and if they did, make sure it is an integer(is_int($zipcode)).
Narch, don't post your problems in more than one forum. It's very bad form.
Nico, you're mistaken, the way he's adding to the array is perfectly valid.
Nick
I had a similar problem, and fixed it by replacing
$zipcode == ""
with
empty($zipcode)
empty() tests for "" and for unset variables as well.
Benji.
It should also be possible to solve it like this:
if (!is_int($zipcode) || !$zipcode){ $error[] = "Zip Code"; //error array }
...since php considers this empty variable as FALSE.
/Anders