Jump to content

Session Var Not Testing True In If


justravis

Recommended Posts

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!";
}

'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!!!!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.