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
https://forums.phpfreaks.com/topic/56998-solved-if-statment-help/
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

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!

 

:)

 

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.