Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php bindParam出现PDO execute()错误_Php_Pdo_Bindparam - Fatal编程技术网

Php bindParam出现PDO execute()错误

Php bindParam出现PDO execute()错误,php,pdo,bindparam,Php,Pdo,Bindparam,我找不到此代码的失败位置 $username = $_POST["UserID"]; $password = $_POST["PWD"]; $sql = 'select COUNT(*) from Staff where UserID = :UserID and PWD = :PWD'; $result = $cnnEmployee->prepare($sql); $result->bindParam(':UsedID',$username, PDO::PARAM_STR)

我找不到此代码的失败位置

 $username = $_POST["UserID"];
 $password = $_POST["PWD"];
 $sql = 'select COUNT(*) from Staff where UserID = :UserID and PWD = :PWD';
 $result = $cnnEmployee->prepare($sql);
 $result->bindParam(':UsedID',$username, PDO::PARAM_STR)
 $result->bindParam(':PWD',$password, PDO::PARAM_STR)
 $result->execute(); //Error here: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'
但是如果我换成

 $username = $_POST["UserID"];
 $password = $_POST["PWD"];
 $sql = 'select COUNT(*) from Staff where UserID = :UserID and PWD = :PWD';
 $result = $cnnEmployee->prepare($sql);
 $result->execute(array(':UserID'=>$username, ':PWD'=>$password));
它很好用
请帮我找出我的问题所在。

当你绑定你使用的参数时
:UsedID
,但是查询中的占位符正在查找
:UserID

你注意到第一个示例中的键入是
:UsedID
,而不是
:UserID
?哦,非常感谢。