dannyluked Posted August 19, 2009 Share Posted August 19, 2009 Hi, I have a code (below). It dosent do what I want it to do! I want the code to show the following: if forumlevel = more than 3 and there is no session called loggedin, echo "Not allowes", exit; if forumlevel = more than 3 and there is a session called loggedin check if the userlevel = the forumlevel or more. If so echo "". If not echo "You cannot view", exit; if forumlevel = 3 or less echo "". <?php include "config.php"; mysql_connect($server, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $forlev = mysql_query("SELECT forumlevel FROM forum WHERE id = '".$_GET['id']."'") or die(mysql_error()); $qry = mysql_fetch_array($forlev); $forumlevel = $qry[forumlevel]; if (isset($_SESSION['loggedin'])){ $uselev = mysql_query("SELECT userlevel FROM ac_users WHERE username = '".$_SESSION['loggedin']."'") or die(mysql_error()); $qry2 = mysql_fetch_array($uselev); $userlevel = $qry2['userlevel']; }elseif(isset($_SESSION['loggedin']) and $userlevel > 3){ echo ""; }elseif(!isset($_SESSION['loggedin']) and $forumlevel > 3){ echo "Not allowed"; exit; } ?> Does anyone know where I have gone wrong? Quote Link to comment Share on other sites More sharing options...
dannyluked Posted August 19, 2009 Author Share Posted August 19, 2009 I forgot to say, This is what the current code does: if user isnt logged in they can see forums where forumlevel is less than 3. (PERFECT) But if user is logged in they can see all forums. (They should only be able to see forums Where forumlevel = userlevel or more) Quote Link to comment Share on other sites More sharing options...
dannyluked Posted August 20, 2009 Author Share Posted August 20, 2009 Is it possible?! Quote Link to comment Share on other sites More sharing options...
Monadoxin Posted August 20, 2009 Share Posted August 20, 2009 <?php include "config.php"; $hDb = mysql_connect($server, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($database, $hDb) or die(mysql_error()); $forlev = mysql_query("SELECT forumlevel FROM forum WHERE id = '".$_GET['id']."'", $hDb) or die(mysql_error()); $qry = mysql_fetch_array($forlev); $forumlevel = $qry[0]; if (isset($_SESSION['loggedin'])) { if($userlevel > 3) { echo ""; } else { $uselev = mysql_query("SELECT userlevel FROM ac_users WHERE username = '".$_SESSION['loggedin']."'") or die(mysql_error()); $qry2 = mysql_fetch_array($uselev); $userlevel = $qry2['userlevel']; } } elseif((!isset($_SESSION['loggedin'])) && ($forumlevel > 3)) { die("Not allowed"); } ?> You had a few small problems that I saw in your code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.