Jas Soloria Jas Soloria - 3 months ago 38
MySQL Question

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean

I'm trying to create a log when connecting to my database, but I get this error:


Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean


Here is the code:

<?php

include 'database.php';
?>

<?php

// create a variable
$email=$_POST['email'];
$password=$_POST['password'];


//Execute the query

$sql = "SELECT * FROM user WHERE email='$email' AND password='$password'";
$result = mysqli_query($connect,$sql);

if(!$row = $result -> fetch_assoc($result)){
echo "Your email or password is incorrect!";
}
else{
echo "You are logged in!";
}


Thank you!

Answer

if you are implementing login code try this instead

$sql = "SELECT * FROM user WHERE email='$email' AND password='$password'";
$result = mysqli_query($connect,$sql);

if(mysqli_num_rows($result) == 1 ){
    echo "You are logged in!";
    }
    else{
    echo "Your email or password is incorrect!!";
    }
Comments