【问题标题】:Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number未捕获的 PDOException: SQLSTATE[HY093]: 无效的参数号
【发布时间】: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'; ?>

【问题讨论】:

标签: php mysql


【解决方案1】:

在prepare语句中,你有三个变量username、password和groupID,而你只绑定了两个变量,所以,你应该在execute语句中添加第三个或删除?为 groupID 并设置一个实际值。

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 2020-08-11
    • 2023-01-27
    • 2016-09-07
    • 2016-11-28
    相关资源
    最近更新 更多