Jump to content

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.

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.