2

We are using below code for "sign up". we have only password field , we want to add confirm password field.

signup.php

if(isset($_POST['btn-signup']))
{
    $uname = trim($_POST['txtuname']);
    $email = trim($_POST['txtemail']);
    $upass = trim($_POST['txtpass']);
    $code = md5(uniqid(rand()));

    $stmt = $reg_user->runQuery("SELECT * FROM tbl_users WHERE userEmail=:email_id");
    $stmt->execute(array(":email_id"=>$email));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);

    if($stmt->rowCount() > 0)
    {
        $msg = "
              email allready exists 
              ";
    }
    else
    {
        if($reg_user->register($uname,$email,$upass,$code))
        {           
            $id = $reg_user->lasdID();      
            $key = base64_encode($id);
            $id = $key;

            $message = "                    
                        some message";

            $subject = "Confirm Registration";

            $reg_user->send_mail($email,$message,$subject); 
            $msg = "
                    some message
                    ";
        }
        else
        {
            echo "sorry , Query could no execute...";
        }       
    }
}

class.usr.php

public function register($uname,$email,$upass,$code)
    {
        try
        {                           
            $password = md5($upass);
            $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode) 
                                                         VALUES(:user_name, :user_mail, :user_pass, :active_code)");
            $stmt->bindparam(":user_name",$uname);
            $stmt->bindparam(":user_mail",$email);
            $stmt->bindparam(":user_pass",$password);
            $stmt->bindparam(":active_code",$code);
            $stmt->execute();   
            return $stmt;
        }
        catch(PDOException $ex)
        {
            echo $ex->getMessage();
        }
    }

I tried adding below code, but it did't worked for me.

$cpass = trim($_POST['txtpass']);

/* Afer if statement */

elseif($pass != $cpass){
             $msg = "passwords doesn't match";
        }

also tried in class.usr.php file, but no luck.....

  • 1
    You are using `trim($_POST['txtpass'])` for both `$pass` and `$cpass` value. Your `$cpass` should be different. Let assume you confirm password input field name is `confirm_password`. So. your `$cpass = trim($_POST['confirm_password'])` – Mahfuzul Alam Oct 06 '16 at 10:10
  • @MahfuzulAlam Thanks for your support..... –  Oct 06 '16 at 11:14

1 Answers1

1
First of all you have not mentioned confirm password field. 
Lets assume your confirm password field is "txtConfirmPass"

Before redirect to register function need to check password and confirm password like

$upass = trim($_POST['txtpass']);
$uConfirmPass = trim($_POST['txtConfirmPass']);

if($upass != $uConfirmPass){

    // Password not match your code here
}else{
    if($reg_user->register($uname,$email,$upass,$code)){           
        $id = $reg_user->lasdID();      
        $key = base64_encode($id);
        $id = $key;

        $message = "some message";

        $subject = "Confirm Registration";

        $reg_user->send_mail($email,$message,$subject); 
        $msg = "some message";
    }
    else
    {
        echo "sorry , Query could no execute...";
    }
}

Hopefully it help you out.
Kishan Patel
  • 485
  • 4
  • 17
  • i am getting this error : `Notice: Undefined index: txtConfirmPass in line : `$uConfirmPass = trim($_POST['txtConfirmPass']);` –  Oct 06 '16 at 10:25
  • is i need to add any code in `class.usr.php` ? or is this problem of using 2 `else if` conditions ? –  Oct 06 '16 at 10:32
  • This "txtConfirmPass" field is for understanding in answer you need to set actual confirm password field in your HTML – Kishan Patel Oct 06 '16 at 10:53
  • looks like its working, id there nay code i need to add in `class.usr.php` ? –  Oct 06 '16 at 11:13