Jump to content

If code not working...


dannyluked

Recommended Posts

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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.