title: php check and validate form input with mysql database
body: <p>Basically I have this form that asks for email and password.</p>
  
  <p>What I want to do is to compare and check if the inputs match with the data from my table/database.</p>
  
  <p>This is my <strong>registration.php (the form)</strong></p>
  
  <pre><code>&lt;form action="Authentication.php" method="post"&gt;
  
      &lt;b&gt;Returning Intern Login&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;
      Enter your e-mail address: &lt;input type="text" name="email" /&gt;&lt;br/&gt;&lt;br/&gt;
      Enter your password: &lt;input type="password" name="pw2"/&gt;&lt;br/&gt;&lt;i&gt;(Passwords are case-sensitive and must be 6 characters long)&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;
  
      &lt;input type="reset" value="Reset Login Form" /&gt;
      &lt;input type="submit" name="submit2" value="Log In" /&gt;&lt;hr/&gt;&lt;br/&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>and this is the <strong>Authentication.php</strong></p>
  
  <pre><code>session_start();
  
  $link = mysqli_connect('localhost','root','');
  $database = mysqli_select_db($link,'internship');
  
  $user = $_POST['email'];
  $pass = $_POST['pw2'];
  
  
  // User is logging in
  if (isset($_POST["submit2"]))
  {
      if (empty ($user)) //if username field is empty echo below statement
      {
          echo "&lt;font color='red'&gt;***You must enter your unique username (email).***&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;";
  
      }
      if (empty ($pass)) //if password field is empty echo below statement
      {
          echo "&lt;font color='red'&gt;***You must enter your unique password.***&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;";
      }
  
  }
  else
  {   
  
      $query = "SELECT * FROM Interns WHERE email = '". mysqli_real_escape_string($link,$user) ."' AND password = '". mysqli_real_escape_string($link,$pass) ."'" ;
      $result = mysqli_query($link,$query);
      if (mysqli_num_rows($result) == 1) 
      {
          echo "pass"; //Pass, do something
      } 
      else 
      {
          echo "fail"; //Fail
      }
  
  }
  
  session_write_close();
  </code></pre>
  
  <p>It works with the empty inputs. </p>
  
  <p>But when I gave an email and password exactly same from the database/table, </p>
  
  <p>It displays white blank page..</p>