vendredi 3 septembre 2021

PHP codeigniter if statement not functioning right

I was trying to creating a login system in CodeIgniter. And for login validation I need to check user passwords with the password stored in database. so after getting data from user and database when I check if passwords is right by comparing them using if statement, It is running code from else part even when password is same.. I print both password in else statement to see and these are exactly same. but if statement runs the else part.

This is the code :

$model=new CrudModel();
        $users = $model->where('Name', $_POST['Name'])->findAll();
        if($_POST['Password'] == $users[0]['Password']){
            echo 'Pasword is OK';
        }   
        else{
            print_r($users);
            echo "<br>";
            echo $users[0]['Password'].'  --- This is from database';
            echo "<br>";
            echo $_POST['Password'].'  --- This is from user login form';
            echo "<br>";
            echo 'pasword is not OK';
        }

And this is result when I enter right Password :

codeigniter if loop error pic-result

Aucun commentaire:

Enregistrer un commentaire