title: PHP checking empty fields Login
body: <p>I have a select action and I want to check if the fields <code>username</code> and <code>password</code> are both empty. My issue is that if one of them is empty echo msg pops but, but if both are empty it goes straight to the next page.</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL &amp; ~E_NOTICE);
  session_start();
  
  if ($_POST['submit']) {
      include_once("connexion.php");
      $username = strip_tags($_POST['username']);
      $password = strip_tags($_POST['password']);
  
      $sql = "SELECT id, username, password  FROM users where username = '$username' and password ='$password'";
      $query = mysqli_query($dbCon,$sql);
  
      if ($query) {
          $row = mysqli_fetch_row($query);
          $userId = $row[0];
          $dbUsername = $row[1];
          $dbPassword = $row[2];
      }
  
      if ($username == $dbUsername &amp;&amp; $password == $dbPassword) {
          $_SESSION['username'] = $username;
          $_SESSION['id'] = $userId;
          header('location:../index-2.php');
      } else {
          echo "wrong username or password";
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Edit : I used Dharmesh Goswami solution :</p>
  
  <pre><code>if ($username == $dbUsername &amp;&amp; !empty($username) &amp;&amp; $password == $dbPassword &amp;&amp; empty($password) )
  </code></pre>
  
  <p>It works like a charm ! Thank you.</p>