Monday, April 9, 2018

php - Fatal error: Call to a member function fetch_assoc() on a non-object

how do i fix this error? this is my code.



$stmt = $this->conn->prepare("SELECT ngno, email, encrypted_password, name, user_type FROM `guide` WHERE email = ?");

$stmt->bind_param("s", $email);

if ($stmt->execute()) {
$user = $stmt->bind_result($ngno, $email, $encrypted_password, $name, $user_type)->fetch_assoc();

$stmt->close();


im using a remote sql database. i have also tried this on my localhost. but then i get the error, fatal error call to a member function fetch_assoc() on boolean



this code worked with get_result instead of bind_result. but i need to use bind_result. Any help would be appreciated.



EDIT 1:



i have changed the code to the following,




$stmt = $this->conn->prepare("SELECT ngno, email, encrypted_password, name, user_type FROM `guide` WHERE email = ?");

$stmt->bind_param("s", $email);

if ($stmt->execute()) {
$stmt->bind_result($ngno, $email, $encrypted_password, $name, $user_type);
$user = $stmt->fetch_assoc();
$stmt->close();


if($encrypted_password == $password){
return $user;
}
} else {
return NULL;
}


i get this error now. Fatal error: Call to undefined method mysqli_stmt::fetch_assoc()




Is my query failing?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...