Search code examples
phpmysqlpdo

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens and i am new ussin pdo for connection to database


    $query="INSERT INTO users (username,pwd,email) values(':userName',':pwd',':Email')";
    $stmt=$pdo->prepare($query);

    $stmt->bindParam(':userName',$username);
    $stmt->bindParam(':pwd',$password);
    $stmt->bindParam(':Email',$email);

    $stmt->execute();

here's my code my parameter are same but it keeps giving me this error

i have tried changing the placeholders names but did not work


Solution

  • In your query you have quotes around the placeholder names, making them into strings.

    If you remove them it should, hopefully, work.

    Like this:

    $query="INSERT INTO users (username,pwd,email) values(:userName,:pwd,:Email)";