title: how to validate the simple php login form with the mysqli query?
body: <p>this  is my php code</p>
  
  <pre><code>&lt;?php
  $con=mysqli_connect("","","","");
  if (mysqli_connect_errno()) {   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }\\check connection
  $username = mysqli_real_escape_string($con, $_POST["username"]); $password=mysqli_real_escape_string($con$_POST["password"]); \\get the input values                                              
  if ($_SERVER["REQUEST_METHOD"] == "POST")\\check for the form method
  {
      session_start();\\start the session 
  if(!empty($_POST["username"]))
  {
      if(!empty($_POST["password"]))
      {\\ if the username and password is not empty,then execute the query
  
      $res=("SELECT * FROM personal WHERE username='".$username."' password='".$password."') or die(mysqli_error());\\get the row value accoring to the input username and password
      if(mysqli_num_rows($res) == 1)\\to check the number of rows, if it is 1 then execute the loop
      {
          $row = mysqli_fetch_array($res,MYSQLI_ASSOC);
          $user = $row['username'];
          $pass = $row['password'];\\assign the row values to the variables
          if ($password != $pass)
          {
         echo"Please Register your details";
          } \\if not match
          else{
              header("Location:home.php");
          }\\else goto home page
      }
      else{
          echo"Enter the Valid Password";\\error message
          }
  }
  else {
      echo"Enter the Valid Username";\\error message
  }
  }
  mysqli_free_result($res);
  }
  mysqli_close($con);\\close connection
  </code></pre>
  
  <p>and my html form is</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt; 
  &lt;head&gt;
  &lt;title&gt;Sign-In&lt;/title&gt;\\title of the page
  &lt;/head&gt;
  &lt;body id="body-color"&gt;
  
  &lt;div id="Sign-In"&gt;
  
  &lt;fieldset style="width:30%"&gt;&lt;legend&gt;LOG-IN&lt;/legend&gt;\\field setup
  
  &lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt;\\open form tag
  
  Username: &lt;br&gt;&lt;input type="text" name="username"  maxlength="50" value="&lt;?php echo $username;?&gt;"&gt;&lt;br&gt;\\get user name
  
  Password: &lt;br&gt;&lt;input type="password" name="password" maxlength="50"value="&lt;?php echo $password;?&gt;"&gt;&lt;br&gt;get the password
  
  &lt;input type="submit" value="Log-In"&gt;\post the details
  &lt;/form&gt;\\close form
  
  &lt;/fieldset&gt;
  
  &lt;/div&gt;
  
  &lt;p&gt;If you are not a exsiting user go to &lt;a href="reg.php"&gt;Register&lt;/a&gt;&lt;/p&gt;\\ link to the next page
  
  &lt;/body&gt;
  
  &lt;/html&gt;\\close html file
  </code></pre>