问题描述:

I have a little question, I'm working on a small login system for school (it's a project). But, I keep getting this error, which I haven't had before, since the retrieving was working. Does anyone of you maybe know the cause of this problem?

The error:

Notice: Trying to get property of non-object in C:\xampp\htdocs\StuffNology-Good\index.php on line 14

<?php

require_once('config.inc.php');

$result = $conn->query("SELECT * FROM users WHERE username='".$sesUser."' OR email='".$sesUser."'");

$row = $result->fetch_object();

if(!$_SESSION['logged_in']) {

?>

<li><a href="register.php">Click here to register</a></li>

<li><a href="login.php">Click here to login</a></li>

<?php

} elseif($_SESSION['logged_in']) {

?>

<li>Weclome <?php echo $row->username; ?>!</li>

<li><a href="profile.php">Click here to view your profile</a></li>

<li><a href="profile.php">Click here to edit your information</a></li>

<li><a href="forgotpass.php">Click here if you forgot your password</a></li>

<?php

}

?>

Thank you very much!

网友答案:

Your problem happens here

$row = $result->fetch_object();

That's not returning an object, likely because of a SQL error. So when you run this

<li>Weclome <?php echo $row->username; ?>!</li>

There's no object to work with. Try this after your query

$result = $conn->query("SELECT * FROM users WHERE username='".$sesUser."' OR email='".$sesUser."'");
echo $conn->error;
相关阅读:
Top