justravis Posted September 9, 2008 Share Posted September 9, 2008 The print_r proves there is 'confirm' session var, but it doesnt test true. #Test #print_r($_SESSION); if($_SESSION[confirm]) { "echo <span class=hi>$_SESSION[confirm]</span>"; } I know...this question deducts cool pts...Thanks. Link to comment https://forums.phpfreaks.com/topic/123389-session-var-not-testing-true-in-if/ Share on other sites More sharing options...
JasonLewis Posted September 9, 2008 Share Posted September 9, 2008 What is in $_SESSION['confirm']? Get in the habbit of putting '' around element names. Instead of: $_SESSION[confirm] It should be: $_SESSION['confirm'] Try using the isset() function. if(isset($_SESSION['confirm'])){ echo "It is set!"; } Link to comment https://forums.phpfreaks.com/topic/123389-session-var-not-testing-true-in-if/#findComment-637296 Share on other sites More sharing options...
justravis Posted September 9, 2008 Author Share Posted September 9, 2008 'confirm' is a string. I should have mentioned I tried isset() before posting, but OF COURSE it works now!!! Winning Code: if(isset($_SESSION['confirm'])) { "echo <span class=hi>$_SESSION['confirm']</span>"; } W if(isset($_SESSION['confirm'])) { echo "<span class=hi>$_SESSION['confirm']</span>"; } Resulted in: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING ..BUT this suddenly works now too..wtf?!?! if($_SESSION[confirm]) { echo "<span class=hi>$_SESSION[confirm]</span>"; } THANKS!!!! Link to comment https://forums.phpfreaks.com/topic/123389-session-var-not-testing-true-in-if/#findComment-637307 Share on other sites More sharing options...
JasonLewis Posted September 9, 2008 Share Posted September 9, 2008 If you are to echo an array, then you do it like so: echo "<span class='hi'>{$_SESSION['confirm']}</span>"; OR echo "<span class='hi'>".$_SESSION['confirm']."</span>"; Also, that first code you posted should fail. Use one of the above. Keep using apostrophes when referring to a key in the array. Link to comment https://forums.phpfreaks.com/topic/123389-session-var-not-testing-true-in-if/#findComment-637312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.