完整错误为: PHP可恢复的致命错误:在第11行的C:\ inetpub \ wwwroot \ storeadmin \ index.php中,类mysqli_result的对象无法转换为字符串。这是在上一页上,用户使用数据库中已经存在的用户名和密码登录。然后将这些数据传递到此页面上。
代码如下:
<?php
//
//
//
session_start();
if (!isset($_SESSION["manager"])) {
header("location: admin_login.php");
exit();
}
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
//$managerID = $_SESSION["id"];
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
//$manager = $_SESSION["manager"];
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
//$password = $_SESSION["password"];
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information
// Connect to the MySQL database
include "../storescripts/connect_to_mysql.php";
$sql = mysqli_query($dbcon, "SELECT * FROM admin_users WHERE username='$manager' AND password='$password'"); // query the person
//print(strval(new $sql));
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysqli_num_rows($sql); // count the row nums
if ($existCount == 0) { // evaluate the count
echo "Your login session data is not on record in the database.";
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Admin Area</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
<?php include_once("../template_header.php");?>
<div id="pageContent"><br />
<div align="left" style="margin-left:24px;">
<h2>Hello <?php echo $manager ?>, what would you like to do today?</h2>
<h3>Your id is: <?php echo $managerID ?></h3>
<h3>Your password is: <?php echo $password ?></h3>
<p><a href="inventory_list.php">Manage Pre-built</a><br />
<a href="components_list.php">Manage Components </a><br />
<a href="add_user.php">Add Users</a></p>
</div>
<br />
<br />
<br />
</div>
<?php include_once("../template_footer.php");?>
</div>
</body>
</html>