Forum Moderators: coopster

Message Too Old, No Replies

if and statement problem

if and statement evaluating true when it should be false

         

MrWhippy

10:51 am on Mar 4, 2009 (gmt 0)

10+ Year Member



Hi all,

Could anyone shed some light on this for me please.

I have the following IF AND statement and it seems to be having issues with at least one of the checks.


if (true == $input_name && true == $input_email && true == $input_con_email && true == $input_pwd && true == $input_con_pwd && true == $input_first && true == $input_last && true == $input_tel && true == $input_club)

the one that is not evaluating properly is the $input_pwd even when it is false the statement still carries out the first set of code, if i change $input_name to false directly then the code executes the second set of code.

I know that $input_pwd is false as at the moment I am echoing before the if and inside it as well.

edit to add following

I just thought I would add I have tried this using the follwoing also to see if that works, and to try and make the code easier to read

[code]
if (true == $input_name && input_pwd && rest of variables)

[edited by: MrWhippy at 10:52 am (utc) on Mar. 4, 2009]

coopster

7:18 pm on Mar 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



At first I thought perhaps you had an Operator Precedence [php.net] or associativity issue, but I don't believe that is the case. Use var_dump [php.net] to dump the value of $input_pwd to the browser and make sure you have a valid comparison there. Better yet, compare only that value first so you can troubleshoot your issue.

if (true == $input_pwd) {
print '$input_pwd is true';
} else {
print '$input_pwd is false';
}
var_dump($input_pwd);
if (true == $input_name && true == $input_email && true == $input_con_email && true == $input_pwd && true == $input_con_pwd && true == $input_first && true == $input_last && true == $input_tel && true == $input_club)

MrWhippy

9:36 pm on Mar 4, 2009 (gmt 0)

10+ Year Member



I was thining of going that way with it,

thanks for the confirmation that it should let me know what is going on.

Thanks for your help on my other post as well, even though that one was a typo i dont believe this one to be so. (hence the reason i copied and pasted the code in)

Ill let you know how i get on

MrWhippy

10:13 am on Mar 10, 2009 (gmt 0)

10+ Year Member



Seem to have it working now, not sure what the problem was think it may have been something earlier in the code affecting it.

thanks for the help again.