I am having trouble with a registration script that I am trying to implement. When I click the "Register" button, I get this error:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

This is my coding for the register function:

`public function register() {
    $correct = false;
        try {
            $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
            $sql = "INSERT INTO users(UserID, Username, Password, Email, Activated) VALUES('', :username, :password, :email, '1')";

            $stmt = $con->prepare( $sql );
            $stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
            $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR );
            //Show Pop Up Box Saying That The Account Has Been Created Successfully
            return ("<SCRIPT LANGUAGE='JavaScript'>
                window.alert('Your account has been created successfully. You may now login.')
        }catch( PDOException $e ) {
            return $e->getMessage();

Please help!

Thanks so much.

Recommended Answers

All 3 Replies

I don't see the bindValue in your code for email.

How and where would I add it? I thought that might be the problem however, I wasn't sure...

Probably this after line 10

        $stmt->bindValue( "email", $this->email, PDO::PARAM_STR );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.