2014-05-08 30 views
0

我有一个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(); 
    } 
?> 

有人能告诉我我做错了什么吗?

+0

您应该从第一行收到语法错误。您不能在'empty()'的参数中使用表达式,它的参数必须是单个变量。 – Barmar

回答

0

它应该是:

if (!empty($_POST['username']) && !empty($_POST['password'])){ 

documentation

此前PHP 5.5,空()只支持变量;其他任何东西都会导致解析错误。

+0

天哪我不相信我忽视了这一点。干杯。 – Lee

0

替换你这个条件:

if (!empty($_POST['username']) && !empty($_POST['password'])){ 
[...]