title: Validate password with confirm password during sign up in php
body: <p>We are using below code for "sign up". we have only <strong>password</strong> field , we want to add <strong>confirm password</strong> field. </p>
  
  <p><strong>signup.php</strong></p>
  
  <pre><code>if(isset($_POST['btn-signup']))
  {
      $uname = trim($_POST['txtuname']);
      $email = trim($_POST['txtemail']);
      $upass = trim($_POST['txtpass']);
      $code = md5(uniqid(rand()));
  
      $stmt = $reg_user-&gt;runQuery("SELECT * FROM tbl_users WHERE userEmail=:email_id");
      $stmt-&gt;execute(array(":email_id"=&gt;$email));
      $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
      if($stmt-&gt;rowCount() &gt; 0)
      {
          $msg = "
                email allready exists 
                ";
      }
      else
      {
          if($reg_user-&gt;register($uname,$email,$upass,$code))
          {           
              $id = $reg_user-&gt;lasdID();      
              $key = base64_encode($id);
              $id = $key;
  
              $message = "                    
                          some message";
  
              $subject = "Confirm Registration";
  
              $reg_user-&gt;send_mail($email,$message,$subject); 
              $msg = "
                      some message
                      ";
          }
          else
          {
              echo "sorry , Query could no execute...";
          }       
      }
  }
  </code></pre>
  
  <p><strong>class.usr.php</strong></p>
  
  <pre><code>public function register($uname,$email,$upass,$code)
      {
          try
          {                           
              $password = md5($upass);
              $stmt = $this-&gt;conn-&gt;prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode) 
                                                           VALUES(:user_name, :user_mail, :user_pass, :active_code)");
              $stmt-&gt;bindparam(":user_name",$uname);
              $stmt-&gt;bindparam(":user_mail",$email);
              $stmt-&gt;bindparam(":user_pass",$password);
              $stmt-&gt;bindparam(":active_code",$code);
              $stmt-&gt;execute();   
              return $stmt;
          }
          catch(PDOException $ex)
          {
              echo $ex-&gt;getMessage();
          }
      }
  </code></pre>
  
  <p>I tried adding below code, but it did't worked for me.</p>
  
  <pre><code>$cpass = trim($_POST['txtpass']);
  </code></pre>
  
  <p>/* Afer if statement */</p>
  
  <pre><code>elseif($pass != $cpass){
               $msg = "passwords doesn't match";
          }
  </code></pre>
  
  <p>also tried in <code>class.usr.php</code> file, but no luck..... </p>