我有一个if语句,只要它是真的,我会重定向到另一个页面。它似乎不适合我。如果语句似乎被忽略
<?php
require 'includes/config.php';
session_start();
if (!empty($_POST['username'] && $_POST['password'])){
$gebruikersnaam = $_POST['username'];
$wachtwoord = $_POST['password'];
}
try{
$conn = new PDO('mysql:host=localhost;dbname=project_sync', $config['DB_USERNAME'], $config['DB_PASSWORD']);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM employee WHERE gebruikersnaam = :gebruikersnaam');
// Bind and Execute
$stmt->execute(array(
'gebruikersnaam' => $gebruikersnaam
));
// Fetch Result
while($result = $stmt->fetch()){
if ($gebruikersnaam == $result['gebruikersnaam'] && $wachtwoord == $result['wachtwoord']){
header('Location: http://localhost/project_sync2/dashboard.php');
exit();
}else{
header('Location: http://localhost/project_sync2/index.php?set=loginerror');
exit();
set=loginerror';
}
}
}catch (PDOExeption $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
有人能告诉我我做错了什么吗?
您应该从第一行收到语法错误。您不能在'empty()'的参数中使用表达式,它的参数必须是单个变量。 – Barmar