Page 1 of 1

PHP If/Else problem

Posted: Thu Apr 03, 2008 5:32 pm
by insanomania911
Greetings,

I don't understand why this VERY simple code doesn't seem to work in PHP:

***** PLEASE USE THE CODE TAG WHEN POSTING *****

Code: Select all

if ($num == '1')
{     
  if($check == 'order')
  { 
    echo "this is order"; 
  }
 else 
 {
  echo "this is payment";
 }
}

I echo $num it is 1 so it goes in the loop and I echo $check it is order but somehow it skips that if statements and the final output will be "this is payment"

Does anybody knows why ?

Thanks,

Re: PHP If/Else problem

Posted: Thu Apr 03, 2008 6:49 pm
by Christopher
Are you sure $check is exactly 'order' and not something like ' order ' ?

Re: PHP If/Else problem

Posted: Thu Apr 03, 2008 6:51 pm
by it2051229
uhhuuuhhhh where did you echo $check? which part of the code?

Re: PHP If/Else problem

Posted: Thu Apr 03, 2008 9:41 pm
by Beauford
Works for me. Check your variables to make sure they are getting the right values.

Code: Select all

$num = 1;
$check = "order";
 
if ($num == '1')
{     
  if($check == 'order')  { 
    echo "this is order"; 
  }
  else {
   echo "this is payment";
 }
}

Re: PHP If/Else problem

Posted: Fri Apr 04, 2008 3:07 am
by JayBird

Re: PHP If/Else problem

Posted: Fri Apr 04, 2008 4:48 am
by sajithmr
Check some things:

1) == is there ? or instead of whether u put a single '=' symbol.

2) for comparing values with type use '===' instead of '=='