Jump to content

[SOLVED] If statment help


tqla

Recommended Posts

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';
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

 

:)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.