I keep getting this error. 'Notice: Trying to get property of non-object in C:\xampp\htdocs\Homework\Sessions\Exercises\Includes\Login.php on line 21'
Here is my code below. I'm trying to connect and log into a mysql database but I keep getting thesame error.
Any ideas? Thanks
<?php
$dbEntries = $_POST;
foreach ($dbEntries as &$entry) {
$entry = dbString($entry);
}
@$db = new mysqli('mysql13.ezhostingserver.com', 'webdata', 'W3bD@t@', 'allicense');
if (mysqli_connect_errno()) {
echo 'Cannot connect to database: ' . mysqli_connect_error();
} else {
$query = "SELECT id AS EmployeeID, first_name AS FirstName, last_name AS LastName
FROM northwind_employees
WHERE email_address = '" . $dbEntries['Email'] .
"' AND password = '" . $dbEntries['Password'] . "'";
$result = $db->query($query);
if ($result->num_rows) {
$row = $result->fetch_assoc();
$msg = 'Logged in as ' . $row['FirstName'] . ' ' . $row['LastName'];
$_SESSION['FirstName'] = $row['FirstName'];
$_SESSION['LastName'] = $row['LastName'];
$_SESSION['EmployeeID'] = $row['EmployeeID'];
if (isset($_POST['Remember'])) {
setcookie('eid', $row['EmployeeID'], time() + 60 * 60 * 24 * 7);
}
} else {
$msg = 'Login Failed';
unset($_POST['LoggingIn']);
$dbEntries = $_POST;
}
}
?>