0
function Checkactive($active){
$db = new Connect;
$result = '';
if(isset($active)){
  if(empty($active)){
  }else{
    $active = stripslashes(htmlspecialchars($active));
      $user = $db -> prepare("SELECT * FROM users WHERE active = :active");
            $user->execute(array(
                'active' => $active
            ));
            $info = $user->fetch(PDO::FETCH_ASSOC);
            if($info['active'] != 'active'){     //line 128
              $hash = $this->generateCode(10);
                $upd = $db->prepare("UPDATE users SET active=:hash WHERE id=:ex_user");
                $upd -> execute(array(
                    'hash' => $hash,
                    'ex_user' => $info['id']    //line 133 
                ));
              echo "sucess";
          }else {
              echo "failer";
          }
    
        }
  }
return $result;
}

I tried to solve it but I can't.

Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\admin\core\classes\user.Class.php on line 128

Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\admin\core\classes\user.Class.php on line 133

function Checkactive($active){
$db = new Connect;
echo "first";

$result = '';
if(isset($active)){
  if(empty($active)){
  }else{
    echo $active;
    $active = stripslashes(htmlspecialchars($active));
      $user = $db -> prepare("SELECT * FROM users WHERE actived = :active");
            $user->execute(array('active' => $active)); //remove array('active' => $active).....then it will work normally
            $info = $user->fetch(PDO::FETCH_ASSOC);
            
            var_dump($info);             // still return bool(false) 
          //   if( $info['actived'] == 'active'){
          //     $hash = $active;
          //       $upd = $db->prepare("UPDATE users SET actived = :hash WHERE id = :ex_user");
          //       $upd -> execute(array(
          //           'hash' => $hash,
          //           'ex_user' => $info["id"]
          //       ));
          //     echo "sucess";
          // }else {
          //   $hash = "two";
          //     var_dump($active);
          //       $upd = $db->prepare("UPDATE users SET actived = :hash WHERE id = :ex_user");
          //       $upd -> execute(array(
          //           'hash' => $hash,
          //           'ex_user' => $info["id"]
          //       ));
          //   var_dump($info);
          //   var_dump($active);
          //     echo "failer";
          // }
      }

}

remove array('active' => $active).....then it will work normally

5
  • 3
    that means your $info is returning true or false, why dont you var_dump($info) to see whats happening? Commented Mar 21, 2021 at 11:05
  • 1
    Note: stripslashes() has absolutely no business being in this code, and htmlspecialchars() is only for HTML escaping when displaying. Do not use it for SQL escaping. You're (correctly) using placeholder values which means this code is completely pointless. Commented Mar 21, 2021 at 11:06
  • 1
    Check that execute() succeeded. It may have failed. Tip: Turn on exceptions with $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Commented Mar 21, 2021 at 11:08
  • Why are you testing $info['active'], your SQL query already select active = $active? Commented Mar 21, 2021 at 12:26
  • #Syscall you are right.. that is a mistake.. after removing it it works perfectly //'active' => $active \\ THANK YOU Commented Mar 21, 2021 at 21:40

1 Answer 1

0

You have error in $user->fetch(PDO::FETCH_ASSOC), so it return FALSE, not array.

After, you are using $info['active'] and $info['id'] as an array, without result validation.

Sign up to request clarification or add additional context in comments.

4 Comments

yes, it return false. pla tell me how to change that in to array.
I can`t know what is the error, it is in Connect::fetch in your code, and you have to debug it.
remove array('active' => $active).....then it will work normally
@Syscall you are right.. that is a mistake.. after removing it it works perfectly //'active' => $active \\

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.