我一直收到这个错误。 '注意:尝试在第21行的C:\ xampp \ htdocs \ Homework \ Sessions \ Exercises \ Includes \ Login.php'中获取非对象的属性 这是我的代码如下。我正在尝试连接并登录到mysql数据库,但我一直遇到同样的错误。
有什么想法吗?感谢
<?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;
}
}
?>