PHP If/Else problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
insanomania911
Forum Newbie
Posts: 1
Joined: Thu Apr 03, 2008 5:29 pm

PHP If/Else problem

Post 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,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP If/Else problem

Post by Christopher »

Are you sure $check is exactly 'order' and not something like ' order ' ?
(#10850)
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: PHP If/Else problem

Post by it2051229 »

uhhuuuhhhh where did you echo $check? which part of the code?
Beauford
Forum Newbie
Posts: 3
Joined: Thu Apr 03, 2008 9:19 pm

Re: PHP If/Else problem

Post 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";
 }
}
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: PHP If/Else problem

Post by JayBird »

User avatar
sajithmr
Forum Newbie
Posts: 1
Joined: Fri Apr 04, 2008 4:43 am
Location: India
Contact:

Re: PHP If/Else problem

Post 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 '=='
Post Reply