Php If语句似乎被忽略了
我有一个if语句,一旦它是真的,我将重定向到另一个页面。这似乎对我不起作用Php If语句似乎被忽略了,php,if-statement,pdo,http-headers,Php,If Statement,Pdo,Http Headers,我有一个if语句,一旦它是真的,我将重定向到另一个页面。这似乎对我不起作用 <?php require 'includes/config.php'; session_start(); if ( !empty($_POST['username'] && $_POST['password']) ){ $gebruikersnaam = $_POST['username']; $wachtwoord = $_POST['passwo
<?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();
}
?>
将您的条件替换为:
if ( !empty($_POST['username']) && !empty($_POST['password']) ){
[...]
应该是:
if ( !empty($_POST['username']) && !empty($_POST['password']) ){
从:
在PHP5.5之前,empty()只支持变量;任何其他操作都将导致分析错误
第一行应该有语法错误。empty()
的参数中不能有表达式,它的参数必须是单个变量。天哪,我不敢相信我忽略了这一点。干杯