It should be:
if ( !empty($_POST['username']) && !empty($_POST['password']) ){
From the documentation:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error.
题
I have an if statement, as soon as it is true I will redirect to another page. It does not seem to work for me.
<?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();
}
?>
Can Anyone tell me what I am doing wrong?
解决方案
It should be:
if ( !empty($_POST['username']) && !empty($_POST['password']) ){
From the documentation:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error.
其他提示
Replace you condition with this:
if ( !empty($_POST['username']) && !empty($_POST['password']) ){
[...]