当管理员登录时,他可以在主页选项卡上看到所有已注册的人员,包括他们的个人详细信息,但是当我导航到电子邮件选项卡并返回到主页选项卡时,所有这些数据都无法看到。我怀疑它与会话有关,任何人都可以帮助我。
以下是管理员登录时的脚本:
<?php
session_start();
include_once 'navrequire.php';
if(isset($_POST['usern']))
{
$usern = $_POST['usern'];
$pass = $_POST['pass'];
//session
$_SESSION['usern']=$usern;
//escaping
$usern = stripcslashes($usern);
$pass = stripcslashes($pass);
$usern = mysql_real_escape_string($usern);
$pass = mysql_real_escape_string($pass);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query1 = "SELECT * FROM admin WHERE username='$usern' AND password='$pass'";
$validator = mysqli_query($conn, $query1)
or die("Error establishing connection" .mysql_error());
$row1 = mysqli_fetch_array($validator);
if($row1['username'] == $usern and $row1['password']== $pass){
echo '<div id="greet">Hello ' .$_SESSION['usern'].'</div> <br><br>';
$sql = "SELECT owner.firstname, owner.middlename, owner.lastname, ownerdetails.cpno, unitmembers.members, unitowner.unitNo, unitowner.squareMtrs
FROM unitowner INNER JOIN (unitmembers INNER JOIN (ownerlogindetails INNER JOIN (ownerdetails INNER JOIN owner ON ownerdetails.ownerDetId = owner.ownerId) ON ownerlogindetails.ownerLogDetId = owner.ownerId) ON unitmembers.unitMemId = owner.ownerId) ON unitowner.unitOwnId = owner.ownerId;";
$result = $conn->query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Middlename</th>
<th>Lastname</th>
<th>Unit Members</th>
<th>Unit No.</th>
<th>Unit Squaremeters</th>
<th>
</tr>";
if ($result->num_rows > 0) {
// output data of each row
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['middlename'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['members'] . "</td>";
echo "<td>" . $row['unitNo'] . "</td>";
echo "<td>" . $row['squareMtrs'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
else {
header("Location: error.php");
}
$conn->close();
}
?>
</center>
这是邮件页面:
<!DOCTYPE html>
<title>Mail</title>
head>
<?php
session_start();
include_once 'navrequire.php';
echo 'Hello ' .$_SESSION['usern'];
?>
</head>
<body>
</body>
</html>
和navrequire.php
<!DOCTYPE html>
<title>headerInc</title>
<style>
body {margin: 0;}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: #4CAF50;
}
/*ul li a:hover:not(.active) {background-color: #111;}
ul li a.active {background-color: #4CAF50;}*/
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
@media screen and (max-width: 600px){
ul li.right,
ul li {float:none;}
}
</style>
<body>
<ul>
<li><a href="adminlog.php">Overview</a></li>
<li><a href="mail.php">Mails</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">?</a>
<div class="dropdown-content">
<a href="destroyer.php">Logout</a>
</div>
</li>
</ul>
<br><br><br>
</body>
</html>
答案 0 :(得分:0)
问题发生在邮件页面。
<?php session_start();
必须在页面的顶部。之前没有HTML。