Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2006, 10:22 AM   PM User | #1
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
IF Statement Help

morning ..

struggiling with some if statements here... don't seem to be doing as they should, think maybe I'm overlooking something you guys may spot ...

In a cookie I have myid .. this is always a number I can display the myid on my page either just by typing $myid or by using the full $HTTP_COOKIE_VARS['myid']. Either way that works fine, and it always shows the correct myid.
The problem I have is my if statements do not take notice of the cookie variable .. I have ...
PHP Code:
if($status==AND $cid=='$myid'){ //here I just include a file } 
if($status==AND $cid=='$myid'){ //here I have a html table with some text in }
if($status==3//here I have another include } 
Now this is very strange .. the first if statement works fine, it only includes the file if status is 2 and the cid (this comes from a DB) is the same as myid, the cookie var.. that works great.. however the second if statement.. ALWAYS prints the table when status is 3... no matter what the cid and myid is, it will always print.. as if it is ignoring the AND.

The third if statement works fine too.
I have tried alterations of the if statements .. for example ...
PHP Code:
if($status==AND $cid==$myid){ //here I just include a file } 
if($status==AND $cid==$myid//here I have a html table with some text in }
if($status==3//here I have another include } 
and ...
PHP Code:
if($status=='2' AND $cid==$HTTP_COOKIE_VARS['myid']){ //here I just include a file } 
if($status=='3' AND $cid==$HTTP_COOKIE_VARS['myid']){ //here I have a html table with some text in }
if($status=='3'//here I have another include } 
. and it still does not work.. it never errors though.
Its very stange that the first if statement works and the second does not.

If anyone can see what I have done wrong, id be very greatful to hear

Thanks kindly,
Sir P
sir pannels is offline   Reply With Quote
Old 02-14-2006, 10:38 AM   PM User | #2
Bio2hazard
New Coder

 
Join Date: Feb 2006
Location: Germany
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Bio2hazard is an unknown quantity at this point
I do not exactly know what the problem is and only can suggest to echo both values for debugging and see.
However I have a simple solution to your problem: elseif !

PHP Code:
if($status==AND $cid=='$myid'){ //here I just include a file 
} elseif($status==AND $cid=='$myid'){ //here I have a html table with some text in }
if($status==3//here I have another include } 
I hope that helps,

- Felix

Edit: I realized that this only works as long as $status does not get changed by the file you are including.

Anyway I would just suggest to place a echo before the if-statement;
Chances are that the problem doesn't lie within the IF structure.

The only thing I could think of ( but really is more than unlikely ) is the ' ' when comparing; you could try to just use $cid == $myid

Eh you tried that already. Sorry I'm slow. Anyway I guess all I can recommend is echoing both values before the IF statement.

Another thing you could try:
PHP Code:
if( ($status==2) && ($cid==$myid)){ //here I just include a file } 
if(($status==3) && ($cid==$myid)){ //here I have a html table with some text in }
if($status==3){ //here I have another include } 

Last edited by Bio2hazard; 02-14-2006 at 10:43 AM..
Bio2hazard is offline   Reply With Quote
Old 02-14-2006, 11:19 AM   PM User | #3
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
Hey Bio...

Thanks your for your time in replying.
I tried the elseif but had same problem so started echo'ing out as you said ...

The problem was ... previously on my page I had ..
PHP Code:
if($status=3){ stuff 
... so the if statement was actually setting status to 3, no matter what. I have changed that to '==' instead of just '=' and still had slight problem, but as you said.. remove the ' ' ... so $cid=='$myid' became $cid==$myid.

And it all works now... urg that missing = gave me ALL THAT trouble haha.

Thank you kindly for you time Bio
P
sir pannels is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:25 AM.


Advertisement
Log in to turn off these ads.