2

can anyone please tell me why when the results are equal then it echo's out the response, but when the results are false then it shows a blank page. I am sure i have gone wrong somewhere.

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';

        }
    }
3
  • Are you using this in a route or controller? Commented Dec 21, 2016 at 13:22
  • Why are you not using Request? Commented Dec 21, 2016 at 13:23
  • If you're just going to look for the first user in the array, you can use first() instead of get(). Then you can drop the [0] from your userDetails. Commented Dec 21, 2016 at 13:26

2 Answers 2

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

should be

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

You're using assignment = instead of comparison == which will always return true

Sign up to request clarification or add additional context in comments.

Comments

0

This would work!

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';
    }
}

Btw, you need to change if(.... = ....) to if(.... == ....). = is for assigning values and == is for comparing values.

Hope this works!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.