0

I got that error "Trying to access array offset on value of type bool" when I create new profile...

$select_stmt=$db->prepare("SELECT name, email FROM users 
                                        WHERE name=:uname OR email=:uemail");
            
            $select_stmt->execute(array(':uname'=>$loginname, ':uemail'=>$email));
            $row=$select_stmt->fetch(PDO::FETCH_ASSOC); 
            
            if($row["name"]==$loginname){
                $errorMsg[]="Name exist";
            }
            else if($row["email"]==$email){
                $errorMsg[]="email already used";   
            }
            else if(!isset($errorMsg))
            {

  • 4
    And that's why it's important to [read the documentation](https://www.php.net/manual/en/pdostatement.fetch.php): "Return Values: The return value of this function on success depends on the fetch type. In all cases, **false is returned on failure**." So before you run any code based on your SQL statement having worked, _verify_ that it even worked by checking `$row === false` (note the triple = there, which test for [identity](https://www.php.net/manual/en/language.operators.comparison.php), not just equality) – Mike 'Pomax' Kamermans Sep 04 '21 at 19:53

0 Answers0