Jump to content


Photo

question about an if() issue


  • Please log in to reply
8 replies to this topic

#1 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 27 July 2006 - 07:15 PM

Ok so have this script here is an example:
<?php
if($cmd == 'add' AND isset($user)) {
//content
} else {
//other
} ?>

well no matter what I do it always acts as if $user is set. Any ideas.

#2 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 27 July 2006 - 07:18 PM

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.

#3 xyph

xyph
  • Staff Alumni
  • Advanced Member
  • 3,712 posts
  • LocationSurrey, BC

Posted 27 July 2006 - 07:19 PM

&& instead of AND?
Everything you need to know about storing user-names and passwords
http://www.openwall....Users-Passwords
Blank Page? Try forcing errors to display
ini_set('display_errors',1);
error_reporting(-1);

#4 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 27 July 2006 - 07:20 PM

haha... or that.

#5 xyph

xyph
  • Staff Alumni
  • Advanced Member
  • 3,712 posts
  • LocationSurrey, BC

Posted 27 July 2006 - 07:32 PM

Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset()
Everything you need to know about storing user-names and passwords
http://www.openwall....Users-Passwords
Blank Page? Try forcing errors to display
ini_set('display_errors',1);
error_reporting(-1);

#6 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 27 July 2006 - 07:50 PM

Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset()


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:
<?php
$cmd = $_GET['cmd'];

//check if loged in
if(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 form

if(($cmd == 'add') && isset($user)) {
//this is where the form goes
} else {
//show page as normall
}
?>[code]


[/code]


#7 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 27 July 2006 - 07:52 PM

never mind... duh. When I changed the AND to && it worked. Where do you use AND anyways?

#8 jcbarr

jcbarr
  • Members
  • PipPipPip
  • Advanced Member
  • 219 posts

Posted 27 July 2006 - 07:58 PM

SQL queries from what I know

#9 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 27 July 2006 - 08:01 PM

I see, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users