我是编码的新手。我正在尝试在接下来的几页上显示用户已保存(注册时)的某些数据。我可以显示用户名,但也要显示名称和电子邮件。
这是用户登录时的时间。
$query = "SELECT * FROM users
WHERE username='$username'
AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: indexclient.php');
}else {
array_push($errors, "Wrong username/password combination");
}
//new page
//This is the top of the page where I want to display the name.
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: loginclient.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: loginclient.php");
}
//This is where I want to display the name at the bottom of the page:
<h2> <?php echo $_SESSION['username']; ?>'s Profile</h2>
<?php echo $_SESSION['firstname']; ?>
<?php if (isset($_SESSION['username'])) {
echo "Hello", $_SESSION['firstname'] ;
}
九州编程
隔江千里