SQL 在第 1 行抛出一个语法错误,准备好的语句“靠近'?,?,?,?)

SQL is throwing a syntax error with prepared statements "near '?,?,?,?) at line 1

我的目标是将用户的登录信息发送到 XAMPP SQL 数据库。数据成功到达但程序抛出错误 "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?,?,?,?)' at line 1"

我一直在寻找这个特定问题的答案,但我还没有找到解决方案。

    $password = $_POST['pwd'];
    $email = $_POST['email'];
    $username = $_POST['uid'];
    $sql = "INSERT INTO users(idUsers, uidUsers, emailUsers, 
    pwdUsers) VALUES (?,?,?,?);";
    $idnum = "";
    $hashpwd = password_hash($password, PASSWORD_DEFAULT);
    $stmt = mysqli_stmt_init($conn);
    mysqli_stmt_prepare($stmt, $sql);
    mysqli_stmt_bind_param($stmt, "ssss",$idnum, $username, $email, 
    $hashpwd);
    mysqli_stmt_execute($stmt);
    if(!mysqli_query($conn, $sql)){

        die(mysqli_error($conn));
        exit();

    }

        else{
            echo("YAY");
    }

PHP 和 SQL 错误日志没有显示任何内容,我检查了其余代码中的错误,这是唯一抛出错误的部分。 似乎有很多关于这个主题的帖子。我已经浏览了很多,但找不到这个问题。

如有任何帮助,我们将不胜感激!

您已经通过调用 mysqli_stmt_execute($stmt) 执行了您的查询;对 mysqli_query 的调用失败,因为该函数用于执行正常(未准备好的)查询,因此 $sql 中的 ? 未被替换。您应该检查对 mysqli_stmt_execute 的调用的 return 状态:

if(!mysqli_stmt_execute($stmt)){
    die(mysqli_error($conn));
    exit();
}
else{
    echo("YAY");
}