Page 1 of 1

[SOLVED] Simple but confusing!

Posted: Mon Jun 14, 2004 1:44 pm
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!

Posted: Mon Jun 14, 2004 1:48 pm
by launchcode

Code: Select all

$allowed_levels = array('1','2','3');
if (in_array($level, $allowed_levels))
{
echo "welcome";
}

Posted: Mon Jun 14, 2004 2:22 pm
by Joe
OK worked great man. Thanks a lot!