slj90 Posted January 18, 2010 Share Posted January 18, 2010 I am trying to write a simple If statement... If the Username (authenticatedUser) is 'admin' then echo 'Admin Panel'... I came up with this, but it isn't working.. <?php if ($_SESSION["authenticatedUser"] = "admin") echo "Admin Panel"; ?> Please could you help? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/ Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Share Posted January 18, 2010 Try <?php if ($_SESSION['authenticatedUser'] = "admin") echo "Admin Panel"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997128 Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 if ($_SESSION["authenticatedUser"] = "admin") is assignment, you need comparision.. if ($_SESSION["authenticatedUser"] == "admin") Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997130 Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 It is recommended to place IF statements within blocks to be more portable and syntactically correct. And as mentioned, you are using the assignment operator "=" instead of the comparrison operator "==" <?php session_start(); //Required if not already in your code. if ($_SESSION['authenticatedUser'] == 'admin') { echo "Admin Panel"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997131 Share on other sites More sharing options...
slj90 Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks alot, It's working now! Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997138 Share on other sites More sharing options...
garethhall Posted January 18, 2010 Share Posted January 18, 2010 What do you get when you echo $_SESSION['authenticatedUser']; Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997153 Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 What do you get when you echo $_SESSION['authenticatedUser']; Shouldn't matter, I believe that wasn't his problem. Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997156 Share on other sites More sharing options...
slj90 Posted January 18, 2010 Author Share Posted January 18, 2010 echo $_SESSION['authenticatedUser']; ..Displays Username of the user currently logged in Quote Link to comment https://forums.phpfreaks.com/topic/188864-if-statement-help/#findComment-997162 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.