Why is somethign so simple failing?

When sent via the form the following is considered correct and it proceeds as normal giving me “This is valid zip code”.

However, if no value is set and the script sets the value of $_GET if fails. Even though when echoed it is exactly as it should be.

[php]if(!isset($_GET[‘zip’])){

$_GET['zip'] = '27858';

$_GET['distance'] = '999';

}

$zip = $_GET[‘zip’];

$distance = $_GET[‘distance’];

echo $zip;
//outputs 27858 when no value set via form

if(preg_match(’/^[0-9]{5}$/’, $zip)){

echo 'This is valid zip code';

else {

echo 'This is not a number';

}
[/php]

The only issue I see, is line 16 you start your if statement and have an opening bracket, but line 20 doesn’t have a closing bracket.

Looking through the code, I don’t see why it would fail otherwise. Unless you are getting empty space. In which case you need to trim the input.

The bracket was an issue when copy and pasteing…

But I did find the issue, not my script so I had no idea they were also setting the zip variable via a $_REQUEST later. Needless to say we got rid of that crap! :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service