【发布时间】:2021-08-08 08:59:38
【问题描述】:
我的问题是当我创建此代码时,出现此错误:
致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效参数 number:绑定变量的数量与中的标记数量不匹配 E:\xampp\htdocs\I100Tech eCommerce\admin\index.php:26 堆栈跟踪:#0 E:\xampp\htdocs\I100Tech eCommerce\admin\index.php(26): PDOStatement->execute(Array) #1 {main} 抛出 E:\xampp\htdocs\I100Tech eCommerce\admin\index.php 在第 25 行
是出现在我面前。错误在 execute() methode 的第 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'; ?>
【问题讨论】:
-
你还应该绑定
groupeID。 -
这个问题被问了很多次:stackoverflow.com/questions/18028706/…。你有 3 个“?”在准备语句中,但您只绑定了 2 个变量。