我有一個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