I'm making an API for my project with php and mssql (sql server). I wrote this code but its giving me erros. I have checked the parameters and the values but I can't see the problem. any help would be appreciated. The error is this: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\wamp\www\sarfeh\api\objects\user.php on line 40 I have marked the line 40 in this code bellow. Ans this is what $hash has: $2y$10$BTog4ZdjkrDsH9Hw/FjuD.myHiz61o6SOUDy4KuvoB2dGDQV9Vl4u
EDIT: If I pass the password without hashing (the 11111), this works, but with hashing I get the error.
function create(){
/
// insert query
$query = "INSERT INTO " . $this->table_name . "
(first_name,last_name,phone,password_hash)
values (:first_name,:last_name,:phone,':password')";
/$this->first_name="arassssh2";
$this->last_name="arasssh2";
$this->phone="326981";
$this->password="111111";
// prepare the query
$stmt = $this->conn->prepare($query);
// bind the values
$stmt->bindParam(':first_name', $this->first_name, PDO::PARAM_STR);
$stmt->bindParam(':last_name', $this->last_name, PDO::PARAM_STR);
$stmt->bindParam(':phone', $this->phone, PDO::PARAM_STR);
$hash = password_hash($this->password, PASSWORD_BCRYPT);
$stmt->bindParam(':password', $hash); //line 40
// execute the query, also check if query was successful
if($stmt->execute()){
return true;
}
return false;
}
'before and after:password. Change ` (:first_name,:last_name,:phone,':password')` to ` (:first_name,:last_name,:phone,:password)`.':password'in your query? Refer this for more info w3schools.com/php/php_mysql_prepared_statements.asp