dannyluked Posted August 19, 2009 Share Posted August 19, 2009 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 More sharing options...
mikesta707 Posted August 19, 2009 Share Posted August 19, 2009 .... 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. Link to comment https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/#findComment-901942 Share on other sites More sharing options...
dannyluked Posted August 19, 2009 Author Share Posted August 19, 2009 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']"'") Link to comment https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/#findComment-901952 Share on other sites More sharing options...
mikesta707 Posted August 19, 2009 Share Posted August 19, 2009 oh your mysql syntax was wrong. change to $result = mysql_query("SELECT userlevel FROM ac_users WHERE username = '" . $_SESSION['loggedin'] . "'"); Link to comment https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/#findComment-901958 Share on other sites More sharing options...
KevinM1 Posted August 19, 2009 Share Posted August 19, 2009 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. Link to comment https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/#findComment-901961 Share on other sites More sharing options...
dannyluked Posted August 19, 2009 Author Share Posted August 19, 2009 Thanks, That worked perfectly! Link to comment https://forums.phpfreaks.com/topic/171014-solved-using-a-double-ifelse-statement/#findComment-901965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.