foreverhex Posted July 27, 2006 Share Posted July 27, 2006 Ok so have this script here is an example:[code]<?phpif($cmd == 'add' AND isset($user)) {//content} else {//other} ?>[/code]well no matter what I do it always acts as if $user is set. Any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/ Share on other sites More sharing options...
thepip3r Posted July 27, 2006 Share Posted July 27, 2006 have you echo'd out $cmd and $user to see what values they hold? and is your problem that your conditional always returns true or that $user is always set? if $user appears to be always set and you have register_globals ON in your php.ini file, then any superglobal ($_GET/$_POST) that has a ['user'] element set will automagically be interpreted by $user. Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64778 Share on other sites More sharing options...
xyph Posted July 27, 2006 Share Posted July 27, 2006 && instead of AND? Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64779 Share on other sites More sharing options...
thepip3r Posted July 27, 2006 Share Posted July 27, 2006 haha... or that. Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64781 Share on other sites More sharing options...
xyph Posted July 27, 2006 Share Posted July 27, 2006 Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset() Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64791 Share on other sites More sharing options...
foreverhex Posted July 27, 2006 Author Share Posted July 27, 2006 [quote author=xyph link=topic=102091.msg404727#msg404727 date=1154028725]Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset()[/quote]Well it know that there isn't a $user set and the script works fine if I take out the isset($user) of the if() statement. Here is my accual code:[code]<?php$cmd = $_GET['cmd'];//check if loged inif(isset($user)) {$addlink = '<center><a href="2minhate.php?cmd=add">Add your own stuff</a></center>';} else {$addlink = '<center><a href="checkuser.php">Login to add your own stuff</a></center>';}//If page = 2minhate.php?cmd=add then show formif(($cmd == 'add') && isset($user)) {//this is where the form goes} else {//show page as normall}?>[code][/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64797 Share on other sites More sharing options...
foreverhex Posted July 27, 2006 Author Share Posted July 27, 2006 never mind... duh. When I changed the AND to && it worked. Where do you use AND anyways? Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64798 Share on other sites More sharing options...
jcbarr Posted July 27, 2006 Share Posted July 27, 2006 SQL queries from what I know Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64800 Share on other sites More sharing options...
foreverhex Posted July 27, 2006 Author Share Posted July 27, 2006 I see, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15825-question-about-an-if-issue/#findComment-64803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.