tqla Posted June 24, 2007 Share Posted June 24, 2007 Hi. I want to look in a DB table called 'Member' for the user session and look at a column named 'status'. If the 'status' column equals 'admin' I want to show a message, if the 'status' column does not equal 'admin' I want to show a different message. I think I am on the right track but it's not working right. The user that I am looking up IS an 'admin' but this code is showing 'message for non-admin' instead of the admin message. $sql = "SELECT status FROM Member WHERE loginName='{$_SESSION['MM_Username']}'"; if ($sql == "admin") { echo 'message for admin'; } else { echo 'message for non-admin'; } Quote Link to comment Share on other sites More sharing options...
game2002 Posted June 24, 2007 Share Posted June 24, 2007 are you sure admin is not spelled 'Admin' in the database? Check your uppercase, lowercase. Quote Link to comment Share on other sites More sharing options...
predator Posted June 24, 2007 Share Posted June 24, 2007 hey man this is what needs to be done $SQL = "SELECT * FROM Member WHERE loginName='".$_SESSION['MM_Username']".'"; $query = mysql_query($SQL) or die("cannot check"); $res = mysql_fetch_assoc($query); $adminChk = $res['status']; if($adminChk == "admin") { //do this if it is admin } else { // do this if it is not admin } IF YOU NEED ANY EXPLAINED JUST ASK regards Mark Quote Link to comment Share on other sites More sharing options...
tqla Posted June 25, 2007 Author Share Posted June 25, 2007 Thanks predator! Totally worked! I did need to modify the following part from: '".$_SESSION['MM_Username']".'"; to: '{$_SESSION['MM_Username']}'"; Man, I still need to get an understanding of this stuff: $query = mysql_query($SQL) or die("cannot check"); $res = mysql_fetch_assoc($query); $adminChk = $res['status']; I really need to learn how $query and mysql_fetch_assoc($query) work. Thanks! Quote Link to comment 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.