You should almost definitely be using ‘&&’ instead of ‘||’ since you
probably want to error when NEITHER value is used. So it’s a logic
error. You want to error when it’s not mail and it is not female… as
it is you will always error because it will always be either not mail or
not female.
Good luck.
Crazy PotHead wrote:
> For some reason, the following code doesn’t work, I’m not sure why, it’s
> function should be self explanitory.
>
>
> PHP code:
> --------------------
> $gender = “male”;
>
> if ($gender != “male” || $gender != “female”) echo ‘error’;
> else echo “all good”;
> --------------------
>
>
> This code always returns false even with the gender variable set to
> male or female.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Thanks for all your responses so quickly, I decided to go with the && solution so I don’t have to reformat my code… I really should have been able to figure this one out on my own, but unfortunately I haven’t touched php for use in a client project for over a year now.
You’re absolutely right , I really have to apologize here, I’ve been having an off day. But on a semi-related side note, it really feels odd in general switching back to php after doing the majority or my programing in ruby (only time I touched php was installing/configuring a few wikis), makes me realize how much easier things are in ruby
I was going to say that the code did work… but then I looked back to that section of my code and saw that I had already put something like what you said.