所以当用户登录时,我正在尝试更新数据库中的一些内容,似乎一切都很好,除了最后一部分,我得到的输出是:
“严重错误未知”和“命令不同步;您现在无法运行此命令”
这是我的代码:
<?php
$user = $_POST['username'];
$pass = $_POST['password'];
$connect = mysqli_connect("localhost","myuser","mypass","somedb");
$query = "SELECT `password` FROM `userauth` WHERE `username`=?";
if($stmt = $connect->prepare($query)){
$stmt->bind_param('s',$user);
$stmt->execute();
$stmt->bind_result($tmp_pass);
$stmt->fetch();
if($tmp_pass===$pass){
$letters = array('a','b','*','x','e','d','z','p','@','#');
$letter_key="";
for($i=0;$i<sizeof($letters);$i++){
$letter_key=$letter_key.$letters[rand(1,sizeof($letters-1))];
}
$key = rand(1341163,9999999);
$key2 = rand(3541,9999);
$complete_key = $key.$letter_key.$key2;
setcookie("key",$complete_key);
setcookie("user",$user);
$query_auth = "UPDATE `userauth` SET `auth_key`=? WHERE `username`=?";
if($stmt_2 = $connect->prepare($query_auth)){
$stmt_2->bind_param('ss',$complete_key,$user);
$stmt_2->execute();
}else{
echo "Critical error, unknown ".mysqli_error($connect);
exit;
}
echo "success";
}else{
echo "Error Invalid Username or Password";
}
}else{
"Database link error";
}
?>
有人可以解释可能是什么问题。是的,我的所有字段都是字符串。
答案 0 :(得分:2)
在$ stmt-&gt; fetch()
之后尝试$ stmt-&gt; close()