Jump to content

[SOLVED] Using a double if/else statement...


dannyluked

Recommended Posts

Hi,

Could anyone help me with code that does this:

 

if there isn't a SESSION['loggedin']

echo "not logged in"

elseif ($userlevel==0)

echo "...";

 

The only problem is that the variable $userlevel is a query and if there is no SESSION it gives an error;

$result = mysql_query("SELECT userlevel FROM ac_users WHERE username = '"$_SESSION['loggedin']"'")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

$userlevel = $row['userlevel']

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/
Share on other sites

....

 

if (!isset($_SESSION['loggedin'])){
echo "not logged in";
exit();
}
else {
$result = mysql_query("SELECT userlevel FROM ac_users WHERE username = '"$_SESSION['loggedin']"'")
or die(mysql_error()); 

$row = mysql_fetch_array( $result );

$userlevel = $row['userlevel'];
if ($userlevel == 0){
echo "..";
}
}

 

EDIT: Oh i see your problem now.

That gives the error:

Parse error: syntax error, unexpected T_VARIABLE in ... on line 62

 

line 62 is this line:

$result = mysql_query("SELECT userlevel FROM ac_users WHERE username = '"$_SESSION['loggedin']"'")

 

Put curly braces (i.e. { }) around $_SESSION['loggedin'] on that line.

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.