title: Notice: Trying to access array offset on value of type null - mysqli_fetch_array?
body: <p>Im having a trouble with a PHP Login form.</p>
  <p>When Username + Password is Correct everything works fine , but when its incorrect it gives an error :</p>
  <blockquote>
  <p>Notice: Trying to access array offset on value of type null in
  /opt/lampp/htdocs/login/process.php on line 20 Login Failed!</p>
  </blockquote>
  <p>I know is something related with the mysqli_fetch_array but i dont know what.</p>
  <p>PHP is last version 7.4.8</p>
  <pre><code>&lt;?php
  // Get values from form in login.php
  
  $username = $_POST['user'];
  $password = $_POST['password'];
  
  // To prevent SQL injection
  $username = stripcslashes($username);
  $password = stripcslashes($password);
  // $username = mysql_real_escape_string($username);
  // $password = mysql_real_escape_string($password);
  
  // Database Connection
  $con = mysqli_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;1234&quot;, &quot;login&quot;);
  
  // Query the Db for username
  $result = mysqli_query($con, &quot;SELECT * FROM users WHERE username = '$username' AND password = '$password'&quot;)
          or die(&quot;Fail to connect to database&quot;.mysql_error());
  $row = mysqli_fetch_array($result);
  if ($row['username'] == $username &amp;&amp; $row['password'] == $password){
      echo &quot;Login succesfull!&quot;;
  } else {
      echo &quot;Login Failed!&quot;;
  }
  </code></pre>