2014-05-08 27 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'])){ 
[...]