我正在尝试将此登录脚本从 mySql 转换为 PDO,并且 SELECT 语句适用于 user_name 但不适用于密码。
显示的错误消息是"SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
“。我需要为此语句以不同方式绑定 $hashedPassword 吗?
<?php
session_start();
//Include database connection details & salt
$password = $_POST['password'];
$hashedPassword = sha1($salt . $password);
try {
$stmt_user = $conn->prepare("SELECT * FROM customer_info WHERE user_name = :user_name and password = :hashedPassword");
$stmt_user->bindValue(':user_name', $_POST['user_name'], PDO::PARAM_STR);
$stmt_user->bindValue(':password', $hashedPassword);
$stmt_user->execute();
session_regenerate_id();
$member = $stmt_user->fetch();
$_SESSION['SESS_USER_ID'] = $member['user_id'];
session_write_close();
header("location: launch_member_account.php");
exit();
}catch(PDOException $e) {
echo $e->getMessage();
}
?>