我已经发布了这个,但是它不完整: 我有一个可以运行的登录系统,但是我需要使其与PDO一起使用! 有谁知道哪里出了问题以及我需要更改什么? 代码的第一部分是旧的(正常工作,但不是PDO) 代码的第二部分是我对pdo的尝试!
<?php
ob_start();
if(isset($_REQUEST['password']))
{
require 'connect.php';
$password =$_REQUEST['password'];
$mail = $_REQUEST['email'];
if(empty($mail) || empty($password)){
header('location: ../login.php?error=empty');
exit();
}
else{
$sql = "SELECT * FROM account WHERE email = ?;";
$stmt = mysqli_stmt_init($connect);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../login.php?error=sqlError");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "s", $mail);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($result)){
$passwordCheck = password_verify($password, $row['wachtwoord']);
if($passwordCheck == false ){
header("Location: ../login.php?error=passwordWrong");
exit();
}
else if($passwordCheck == true){
session_start();
$_SESSION['userId'] = $row['account_id'];
$_SESSION['username'] = $row['gebruikersnaam'];
header("Location: ../index.php?login=succes");
exit();
}
}
else{
header("Location: login.php?error=noUser");
exit();
}
}
}
}
else{
header("Location: ../login.php?error=fail");
exit();
}
第二部分:
<?php
ni_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
ob_start();
if(isset($_REQUEST['password']))
{
require 'connect.php';
$password =$_REQUEST['password'];
$mail = $_REQUEST['email'];
if(empty($mail) || empty($password)){
header('location: ../login.php?error=empty');
exit();
}
else{
$sql = "SELECT * FROM account WHERE email = ?;";
$stmt = $connect->prepare($sql);
$stmt->bindParam('?', $mail);
$stmt->execute();
$row_length-> $stmt->fetchColumn();
$row = $stmt->fetchColumn();
if($row_length == 1 ){
$passwordCheck = password_verify($password, $row['wachtwoord']);
if($passwordCheck == false ){
header("Location: ../login.php?error=passwordWrong");
exit();
}
else if($passwordCheck == true){
session_start();
$_SESSION['userId'] = $row['account_id'];
$_SESSION['username'] = $row['gebruikersnaam'];
header("Location: ../index.php?login=succes");
exit();
}
}
else{
header("Location: login.php?error=noUser");
exit();
}
}
}
else{
header("Location: ../login.php?error=fail");
exit();
}
我没有收到错误消息,只是HTTP错误500
答案 0 :(得分:0)
如果您遇到500错误,我的第一个怀疑是:
ni_set('display_errors', 1);
我希望这会引起问题,因为它应该是ini_set