Hello

I have this error

warning: trying to access array offset on value of type bool in sql.php on line 195

it appears between all pages while I am navigating from one page to another, this error appears and disappears immediately, but it appears and remains present when viewing sales reports page.

/*--------------------------------------------------------------*/
  /* Function for checking which user level has access to the page
  /*--------------------------------------------------------------*/
   function page_require_level($require_level){
     global $session;
     $current_user = current_user();
     $login_level = find_by_groupLevel($current_user['user_level']);
     //if user not login
     if (!$session->isUserLoggedIn(true)):
            $session->msg('d','Please Sign in');
            redirect('index.php', false);
      //if Group status Deactive
     elseif($login_level['group_status'] === '0'):  //Line 195
           $session->msg('d','User Banned');
           redirect('home.php',false);
      //checking logged in User level and Require level is Less than or equal to
     elseif($current_user['user_level'] <= (int)$require_level):
              return true;
      else:
            $session->msg("d", "Error");
            redirect('home.php', false);
        endif;

     }

    So whatever find_by_groupLevel does it is for some reason returning a boolean value instead of an array. Probably false because it's supposed to be returning a database query that failed for some reason, and your code doesn't do anything to check for that.

    Not knowing how that function is written, I can only suggest you look at the part of the manual relevant to how you're communicating with the database to see how to collect the error information that the dbms would be sending back instead of the results you're assuming.

    Weedpacket
    find_by_groupLevel
    It is to determine if the one who logging in is an admin or a seller or a user to display the home page that should appear to him according to his group(permission) level.

      Weedpacket

      well, the expected value it should return is 0 or 1 to check if the user is allowed to log in or is banned, but for some reason it doesn't work, I mean if you banned the user he will be able to login.

      consider that I am still a beginner.

        It's not a case of $current_user['user_level'] being a Boolean true or false; rather it's a case that $current_user itself is not an array, but instead is a Boolean. Without knowing what the find_by_groupLevel() function does and whether the Boolean it returns is expected, a special case you need to test for, or just a plain bug can only be speculated on by us without seeing its code. (My guess for now is that it returns false when it runs into a problem.)

          Thanks a lot everybody I fixed it, it was because the PHP version.

            Write a Reply...