I have created a simple mySQL database, and I am trying to insert some test data into it using PHP. When I ran the method on Firefox I got the following message, and I can not resolve this problem:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number:
My method to insert sample into my datebase is:
public function confirmInsert(){
$admin="admin";
$pass="12345v";
$mail="admin@example.com";
$insertSQL = "INSERT INTO 'users' ('user_name', 'user_pass, 'user_email')
VALUES (
:admin,
:pass,
:mail)";
try {
$stmt = $this->db->prepare($insertSQL);
$stmt ->bindParam(':user_name',$admin, PDO::PARAM_STR);
$stmt ->bindParam(':user_pass', $pass, PDO::PARAM_STR);
$stmt->bindParam(':user_email', $mail,PDO::PARAM_STR);
$stmt->execute();
$stmt->closeCursor();
return TRUE;
} catch (Exception $e) {
$e -> getMessage();
}
}
I am running on //localhost, and using apache 2.2 and php 5.2.17. Thanks!!
‘You don’t have the same name for your parameters in the query and when you bind them. You also have to remove the quotes around the fields name in the query.
Should be better that way: