Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter nu



我的问题是,当我创建这个代码,这个错误:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter数量:绑定变量的数量与中的令牌数量不匹配E:xampphtdocsI100Tech eCommerceadminindex.php:26 Stack trace: #0E: xampp 根 I100Tech电子商务 admin index . php (26):PDOStatement->execute(Array) #1 {main}抛出E:xampphtdocsI100Tech eCommerceadminindex.php on line 25

出现在我面前。错误在execute()方法的第25行。我不明白这个错误和如何修复它,谢谢:)

<?php 
session_start();
$nonavbar='';
$pagetitle = 'Login';
include "init.php";
// check if user coming frpm http request
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = $_POST['user'];
$password = $_POST['pass'];
$hashedpass = sha1($password);
// check if the user exist in the database
$stmt = $con->prepare("SELECT 
userID,username,password
FROM 
users 
WHERE  
username = ?  
AND 
password = ?
AND 
groupeID=? 
LIMIT 1");

$stmt->execute(array($username,$hashedpass));//error in this line
$row = $stmt->fetch();
$count = $stmt->rowCount();
// if count > 0 this mean the database conain record about this username
if($count > 0){
$_SESSION['username'] = $username;//register session name
$_SESSION['ID'] = $row['userID'];
header('Location: dashboard.php');// redirect link for user
exit();
}
}
?>
<form class="login" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<h4 class="text-center">Admin Login</h4>
<input class="form-control" type="text" name="u" placeholder="user name" autocomplet="off"/>
<input class="form-control" type="password" name="pass" placeholder="password" autocomplet="new-password"/>
<input class="btn btn-primary btn-block" type="submit" name="user" value="login"/>
</form>


<?php include $tpl . 'footer.php'; ?>

在prepare语句中,您有三个变量username, password和groupID,并且您只绑定了两个变量,因此,您应该在execute语句中添加第三个变量或删除?

相关内容

最新更新