Re: Form Validation Issues
| From: | Richard Lynch | Date: | Thu, 24 May 2007 22:40:51 +0000 |
| Subject: | Re: Form Validation Issues | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255584@lists.php.net to get a copy of this message | ||
On Wed, May 23, 2007 7:41 am, kvigor wrote:
> if($value != 'Alabama' || $value!= 'AL' || $value != 'Alaska'
> ||
This mess will *ALWAYS* evaluate to TRUE, because the $value is ALWAYS
only one value, and thus the other 99 values are going to evaluate to
TRUE and you have || between them...
So you have:
TRUE || TRUE || TRUE || FALSE || TRUE || TRUE ... || TRUE
which is always gonna boil down to TRUE.
You wanted && instead of ||
Actually, it would be MUCH better imho to set up a couple arrays like:
$states = array('Alabama', 'Alaska', ...);
$sts = array('AL', 'AK', ...);
if (!isset($states[$value]) && !isset($sts[$value])){
echo "Bad Dog!";
}
YMMV
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?