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? Link to comment https://forums.phpfreaks.com/topic/171052-if-code-not-working/ 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) Link to comment https://forums.phpfreaks.com/topic/171052-if-code-not-working/#findComment-902145 Share on other sites More sharing options...
dannyluked Posted August 20, 2009 Author Share Posted August 20, 2009 Is it possible?! Link to comment https://forums.phpfreaks.com/topic/171052-if-code-not-working/#findComment-902478 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. Link to comment https://forums.phpfreaks.com/topic/171052-if-code-not-working/#findComment-902616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.