title: How to compare entered password in input login field with the md5 password stored in database?
body: <p><strong>UPDATE(solved): Previously I set the password length to 15 characters where it should be 32 character since the password is encrypted to md5. Now it works fine. Thanks for all the answers and suggestions.</strong></p>
  
  <p>Below is the register php code. The code works fine and able to store password in the database in md5.</p>
  
  <pre><code>  &lt;html&gt;
  &lt;?php
  error_reporting(0);
  if($_POST['submit'])
  {
      $name = mysql_real_escape_string($_POST['name']);
      $username = mysql_real_escape_string($_POST['username']);
      $password = mysql_real_escape_string($_POST['password']);
      $password1 = mysql_real_escape_string($_POST['password1']);
  
      $enc_password = md5($password);
  
      if($name &amp;&amp; $username &amp;&amp; $password &amp;&amp; $password1)
      {
          if(strlen($name)&lt;30)
          {
              if(strlen($username)&lt;10)
              {
                  if(strlen($password)&lt;15 || strlen($password)&gt;6)
                  {
                      if($password == $password1)
                      {
                          require "dbc.php";
                          $query = mysql_query("INSERT INTO users VALUES ('$name','$username','$enc_password')");     
                          echo "Registration Complete! &lt;a href='index.php'&gt;Click here to login&lt;/a&gt;";
                      }
                      else
                      {
                          echo "Passwords must match";
                      }
                  }
                  else
                  {
                      echo "Your password must be between 6 and 15 characters";   
                  }
              }
              else
              {
                  echo "Your username is too long";   
              }
          }
          else
          {
              echo "Your name is too long";
          }
      }
      else
      { 
          echo "All fields are required"; 
      }
  }
  
  ?&gt;
  
      &lt;form action="register.php" method="POST"&gt;
          Name: &lt;input type="text" name="name" value="&lt;?php echo "$name"; ?&gt;"&gt; Max Length:30&lt;p&gt;
          Username: &lt;input type="text" name="username" value="&lt;?php echo "$username"; ?&gt;"&gt; Max Length:10&lt;p&gt;
          Password: &lt;input type="password" name="password"&gt; Max length:15&lt;p&gt;
          Re-Enter Password: &lt;input type="password" name="password1"&gt;&lt;p&gt;
          &lt;input type="submit" name="submit" value="Register"&gt;
      &lt;/form&gt;
      &lt;input type="button" value="&lt;&lt; Back to Login Area" onclick="window.location='../login%20and%20registration/members.php'"&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Below is the login php code.</p>
  
  <pre><code>    &lt;?php
  
  session_start();
  
  require "dbc.php";
  
  $username = mysql_real_escape_string($_POST['username']);
  $password = mysql_real_escape_string($_POST['password']);
  $enc_password = md5($password);
  
  if($username&amp;&amp;$password)
  {
      $query = mysql_query("SELECT * FROM users WHERE username='$username'");
      $numrow = mysql_num_rows($query);
  
  if($numrow!=0)
  {
      while($row = mysql_fetch_assoc($query))
      {
          $db_username = $row['username'];
          $db_password = $row['password'];
      }
  
      if($username==$db_username&amp;&amp;$password==$db_password)
      {
          //echo "Logged in &lt;a href='members.php'&gt;Click here to enter the members area&lt;/a&gt;";
          $_SESSION['username']=$db_username;
          header("location: members.php");
      }
      else 
      {
          header("location: index.php?error=Incorrect Password");
      }
  }
  else 
  {
      header("location: index.php?error=That user doesn't exist");
  }
  }
  
  else 
  {
      header("location: index.php?error=All fields are required");
  }
  
  ?&gt;
  </code></pre>
  
  <p>The problem is I kept getting  the "Incorrect Password" when I try to log in. I think theres something with retrieving the password from the database. Anyone can help?</p>