[SOLVED] Simple but confusing!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

[SOLVED] Simple but confusing!

Post by Joe »

I am creating an admin panel for my site and I have came across some silly error that I just cannot seem to pass. What it is, is that I want only users with a level of 1 or 2 to access the panel otherwise the user is informed with an error message. The code that I cannot seem to pass go's like:

Code: Select all

$sql = "SELECT * FROM members WHERE username = '".$_SESSION['username']."'";
      $result = mysql_query($sql) or die("Error!");
      
      if (mysql_num_rows($result))
      {
       $row = mysql_fetch_assoc($result);
       $level1 = $row['level'];
      }

      if ($level != '1' || $level != '2')
      {
       echo "You are not allowed to access this area of the site!<p>";
       echo "Click <A href='http://www.site.com/index.php'>here</A> to go to the index page!";
       exit;
      }
      ?>
I was thinking perhaps an array with the numbers 1 and 2 but I am not too sure on how I would go about doing that. Any help appreciated!
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Code: Select all

$allowed_levels = array('1','2','3');
if (in_array($level, $allowed_levels))
{
echo "welcome";
}
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

OK worked great man. Thanks a lot!
Post Reply