我正在尝试使用md5密码登录这个帐户。但是错误始终显示无效的参数号。我的密码有什么问题吗?
<?php
include_once '../database.php';
include_once 'reg_Customer.php';
session_start();
if(isset($_SESSION["CustomerName"]))
{
header("location:index.php");
}
try
{
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST["login"]))
{
if(empty($_POST["CustomerName"]) || empty($_POST["CustomerPass"]))
{
$message = '<label>All fields are required</label>';
}
else
{
$query = "SELECT * FROM customer WHERE CustomerName = :CustomerName AND CustomerPass = ".md5(CustomerPass)."";
$stmt = $conn->prepare($query);
$stmt->execute(
array(
'CustomerName' => $_POST["CustomerName"],
md5('CustomerPass') => $_POST["CustomerPass"]
)
);
$count = $stmt->rowCount();
if($count > 0)
{
$_SESSION["CustomerName"] = $_POST["CustomerName"];
header("location:index.php");
}
else
{
$message = '<label>Wrong Password</label>';
}
}
}
}
catch(PDOException $error)
{
$message = $error->getMessage();
}
?> 错误:
SQLSTATEHY093:无效的参数号:绑定变量的数量与令牌
的数目不匹配
发布于 2021-06-29 15:46:28
在定义查询时,实际上已经设置了该值:
[...] AND CustomerPass = ".md5(CustomerPass)."";一定是[...] AND CustomerPass = :CustomerPass。
另外,在数组中,您使用的是键上的MD5散列函数,而不是值。它必须是:
'CustomerPass' => md5($_POST["CustomerPass"])除此之外,不要像md5已经说过的那样使用IMSoP。password_hash是您的朋友,或者是其他哈希函数,如SHA2-512。
https://stackoverflow.com/questions/68181771
复制相似问题