2016-12-21 50 views
2

任何人都可以請告訴我爲什麼當結果相同時,它會迴應出響應,但當結果爲假時,它會顯示一個空白頁。我確信我在某個地方出了問題。laravel如果陳述不起作用

if(isset($_GET['EX1']) && $_GET['EX2'] != ""){ 

     $Email = $_GET['EX1']; 
     $Password = $_GET['EX2']; 

     $userDetails = DB::table('applicants') 
      ->where('Email', '=', $Email) 
      ->where('Password','=', $Password) 
      ->get(); 

     if($Email = $userDetails[0]->Email && $Password = $userDetails[0]->Password){ 

      echo 'Both are the same '; 

     }else{ 

      echo 'Not the same'; 

     } 
    } 
+0

你的路線或控制器使用呢? –

+0

你爲什麼不使用'Request'? –

+0

如果你只是要尋找數組中的第一個用戶,你可以使用'first()'而不是'get()'。然後你可以從userDetails中刪除'[0]'。 – aynber

回答

0

這會奏效!

public function myfunction(Request $request) { 
    if(!empty($request->EX1) && !empty($request->EX2)){ 

     $Email = $request->EX1; 
     $Password = $request->EX2; 

     $userDetails = DB::table('applicants') 
      ->where('Email', '=', $Email) 
      ->where('Password','=', $Password) 
      ->get(); 

     if($Email == $userDetails[0]->Email && $Password == $userDetails[0]->Password){ 

      return 'Both are the same '; 

     }else{ 

      return 'Not the same'; 

     } 
    } else { 
     return 'error'; 
    } 
} 

順便說一句,你需要改變if(.... = ....)if(.... == ....)=用於分配值,而==用於比較值。

希望這個作品!

2
if($Email = $userDetails[0]->Email && $Password = $userDetails[0]->Password){ 

應該

if($Email == $userDetails[0]->Email && $Password == $userDetails[0]->Password){ 

您正在使用的,而不是比較==分配=這將始終返回true