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
?哦,非常感谢。