title: PHP error when trying to login with email that is not in database
body: <p>I have a code below</p>
  <pre><code>//When user clicks on login button
   if(isset($_POST['login-btn'])){
     $email = $mysqli-&gt;real_escape_string($_POST['email']);
     $password = $mysqli-&gt;real_escape_string($_POST['password']);
  
  
     if(empty($email)){
       $errors['email'] = &quot;Email field is required&quot;;
     }
     if(empty($password)){
       $errors['password'] = &quot;Password field is required&quot;;
     }
  
  
     if(count($errors) == 0){
      $sql = &quot;SELECT * FROM accounts WHERE email=? LIMIT 1&quot;;
      $stmt = $mysqli-&gt;prepare($sql);
      $stmt-&gt;bind_param('s', $email);
      $stmt-&gt;execute();
      $result = $stmt-&gt;get_result();
      $user = $result-&gt;fetch_assoc();
      if(password_verify($password, $user['password'])){
        $_SESSION['isLoggedin'] = true;
        $_SESSION['name'] = $user['name'];
        $_SESSION['birthday'] = $user['birthday'];
        $_SESSION['id'] = $user['id'];
        $_SESSION['email'] = $user['email'];
        $_SESSION['username'] = $user['username'];
        $_SESSION['verified'] = $user['verified'];
        header('location: index.php');
        exit();
      }
      else
      {
        $errors['wrongcred'] = &quot;Wrong email/password combination&quot;;
      }
     }
  
  
  }
  </code></pre>
  <p>I have declared $errors array for email and password.  $errors['email'] = &quot;Email field is required&quot; - If email field is left empty,   $errors['password'] = &quot;Password field is required&quot; - If password field is left empty, $errors['wrongcred'] = &quot;Wrong email/password combination&quot; - If user enters wrong credentials. When I enter email address that exists in database but wrong password its works as intended - shows that user entered wrong email/password combination. The problem is that when I enter email address that not exists in database, php gives me this &quot;Notice: Trying to access array offset on value of type null&quot;, I want it to display as $errors array that user entered wrong email/password combination.</p>