Simple IF statement
Posted: Tue Jun 13, 2017 3:52 am
Can someone please point me in the right direction with a basic IF statement please? I'm new to PHP and just can't see what i'm doing wrong?
I've assigned a value to a $_SESSION variable and all I need to do is check what value it is. I've tried 1, 2 or 3 '=' signs, with and without single and double quotes... I can't think of anything else! Could someone please please PLEASE tell me what i'm doing wrong?!? This is the code i'm testing it with:
session_start();
$_SESSION['testVariable'] = "1";
if ($_SESSION['testVariable'] = "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] == "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] === "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] = '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] == '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] === '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
I've tested it with a normal variable, but as soon as it is a $_SESSION, it goes wonky?!? Is there a special syntax I am suppose to use for sessions?
Thank you all in advance, let me know if you need any more info!
I've assigned a value to a $_SESSION variable and all I need to do is check what value it is. I've tried 1, 2 or 3 '=' signs, with and without single and double quotes... I can't think of anything else! Could someone please please PLEASE tell me what i'm doing wrong?!? This is the code i'm testing it with:
session_start();
$_SESSION['testVariable'] = "1";
if ($_SESSION['testVariable'] = "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] == "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] === "2"){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] = '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] == '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
if ($_SESSION['testVariable'] === '2'){echo "IF statement DOESN'T WORK! This is printing!<br>";}
I've tested it with a normal variable, but as soon as it is a $_SESSION, it goes wonky?!? Is there a special syntax I am suppose to use for sessions?
Thank you all in advance, let me know if you need any more info!