PHP错误:绑定变量数与令牌数不匹配。
我在这里缺少什么?我正在尝试为我的med应用程序添加新用户。
public function register($uname,$umail,$upass,$fname,$llastname)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->conn->prepare("INSERT INTO users(name, lastname, user_name, user_email, user_pass) VALUES(:fname, :llastname, :uname, :umail, :upass)");
$stmt->bindparam(":fname", $fname);
$stmt->bindparam(":llastname", $llastname);
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function doLogin($uname,$umail,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT name, lastname, user_id, user_name, user_email, user_pass FROM users WHERE name=:fname, lastname=:llastname, user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if(password_verify($upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
//HTTPS
echo $e->getMessage();
}
}
addUser.php我绑错了吗?
$uname = strip_tags($_POST['txt_uname']);
$umail = strip_tags($_POST['txt_umail']);
$upass = strip_tags($_POST['txt_upass']);
$fname = strip_tags($_POST['txt_fname']);
$llastname = strip_tags($_POST['txt_llastname']);
答案 0 :(得分:1)
下面:
AADSTS70001: Application with identifier 'd340f0ed-5eb3-43e8-9a50-c449649f3ee1' was not found in the directory <MY_TEST_TENANT>
您使用4个(4个!)参数:$stmt = $user->runQuery("SELECT name, lastname, user_name,user_email
FROM users
WHERE name=:fname,
lastname=:llastname,
user_name=:uname
OR user_email=:umail");
,:fname
,:llastname
,:uname
然后,在执行它时,你只能绑定2(两个)参数:
:umail
这正是您收到错误的原因。
顺便提一下,你的SQL查询是错误的。您应该使用$stmt->execute(array(':uname' => $uname, ':umail' => $umail));
加入,
条件,而不是AND
(逗号)。像这样:
WHERE
虽然,我不完全确定那里的AND和OR,你可能需要使用parantheses来实现你需要的逻辑