0
I have the following error "Trying to get Property of non-object on line 22" in the following code:
<?php
require('config.php');
if (isset($_POST['email']))
{
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($conn,$email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($conn,$password);
$stmt = $conn->prepare("SELECT password FROM registo WHERE email=?");
$stmt->bind_param("s",$email);
$email = $_POST['email'];
$stmt->execute();
$result= $stmt->store_result();
if($stmt->affected_rows > 0)
{
$user = mysqli_stmt_bind_result($stmt, $pass);
if(password_verify($password,$pass))
{
$_SESSION['email'] = $email;
$_SESSION['user'] = true;
header("Location: home.php");
same mistake:
<?php while($books =mysqli_stmt_fetch($stmt)){?>
<?php $id = $id +1;?>
<tr>
<td><?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $books->Image).'"height="100" width="100">'; ?> </td> //linha 92
I’ve tried many ways and I can’t seem to solve.
But the function
mysqli_stmt_fetch
returnsbool
, not an object.– Woss
how do I return an object? sorry I’m new at this
– Diana Madeira
Try replacing line 21 with
mysqli_stmt_bind_result($stmt, $pass)
and on line 22 instead of using$user->password
, use$pass
only.– Woss
That line
$email = $_POST['email'];
must be before:$stmt->bind_param("s",$email);
– rray
Anderson with his suggestion and with the rray modified my code. With Anderson’s suggestion there is no more error, however it says that the email/password are wrong. This is code that of a log in form. before I applied the bind Parameter gave no error and entered with the credentials. but now even though I’m not making any mistakes, it says that credentials aren’t right and that’s not true!
– Diana Madeira
You generated the value stored in the database with the function
password_hash
? If yes, is there any way to verify exactly what values are arriving in the condition? Usevar_dump
the two variables and adie
to finalize the request.– Woss
Anderson, I think the password problem already solved. but now suggested the same problem "Trying to get Property of non-object" on line 92. In WHILE I tried to apply the same solution that Voce suggested earlier but still gives the same error. PF see edited the code to add the remaining code where
– Diana Madeira
Gives the same error because you did the same wrong way. The function does not return an object, you need to pass the desired variables by parameter. In the first comment I Linkei the documentation of the function, please. read it.
– Woss