ProtectorOfTheRealm
ProtectorOfTheRealm

Reputation: 11

Can't find the values of my variable

So I have a login page and I am trying to display the values of the $usercheck and $passwordcheck that I made but they won't show

<?php 
 include_once ('includes/head.php');
if(isset($_POST["login"])) {
    $email = $_POST["email"];
    $password = $_POST["password"];

    $query = $pdo->prepare("SELECT `id`, `password`, `email` FROM `users` WHERE `email` = :email AND `password` = :8gEwsko93_37554d ORDER BY `id` LIMIT 1");
    $query->bindValue(":email", $email);
    $query->bindValue(":8gEwsko93_37554d", $password);
    $query->execute();

    $passwordcheck = $query->fetch(PDO::FETCH_ASSOC);

    if($query->rowCount() == 0){
    echo "No user";
    } else {
    if($passwordcheck == $password) {

    $query = $pdo->prepare("SELECT * FROM `users` WHERE `email` = :email AND `password` = :8gZwsZo93_3Z5Zs4d ORDER BY `id` LIMIT 1");
    $query->bindValue(":email", $email);
    $query->bindValue(":8gZwsZo93_3Z5Zs4d", $password);
    $query->execute(); 

    $usercheck = $query->fetch(PDO::FETCH_ASSOC);
    print_r($passwordcheck);
    var_dump($usercheck);
    }
 }

}
?>

Upvotes: 1

Views: 50

Answers (2)

Leandro Papasidero
Leandro Papasidero

Reputation: 3738

Please change

if($passwordcheck == $password)

To

   if($passwordcheck['password'] == $password)

Where 'password' is the column name

Upvotes: 1

Tomas M
Tomas M

Reputation: 7343

At line 17 in your example, you're comparing $passwordcheck, which is a result of $query->fetch() [thus possibly an array, since it fetches whole row] with $password, which is string. Such comparison is always false for nonempty $password. Thus your section with print_r() is never reached.

Upvotes: 1

Related Questions