您好我正在尝试编写一个显示登录用户信息的帐户页面。这就是我到目前为止所做的:
<?php
include 'housestyle.php';
include 'connection.php';
global $mysqli;
?>
<style>
h1
{
font-size: 27px;
}
</style>
<h1>Your Account</h1>
<?php
$profile=$_SESSION['userlogged'];
$query="SELECT * FROM Users WHERE Username=" . $profile . "";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)) {
print_r($row);
}
?>
$ _SESSION ['userlogged'];来自loginsubmit.php:
<?php
session_start();
?>
<font face="ClearSans-Thin">
<font color="lightgray">
<?php
include 'connection.php';
include 'loginform.php';
?>
<center>
<?php
if (isset($_POST['submit']))
{
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "SELECT COUNT(*) AS cnt FROM Users WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' && Password='" . mysqli_real_escape_string($connection, $pass). "'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$queryadmin = "SELECT COUNT(*) AS cnt FROM Admin WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' && Password='" . mysqli_real_escape_string($connection, $pass). "'";
$resultadmin = mysqli_query($connection, $queryadmin);
$rowadmin = mysqli_fetch_assoc($resultadmin);
if ($row["cnt"] > 0)
{
$_SESSION["userlogged"] = $user;
header("Location: homepage.php");
}
else if ($rowadmin["cnt"] > 0 )
{
$_SESSION["adminlogged"] = $user;
header("Location: homepage.php");
}
else
{
echo 'Not a valid login';
}
}
?>
</center>
所以我试图让它识别在登录和会话启动时输入的用户名,然后用它来返回该行的所有内容。我哪里错了?
答案 0 :(得分:1)
在上面的脚本中,您没有session_start()
,因此$_SESSION
为空。