登录后我很难显示用户的个人资料。我只能在会话中显示用户电子邮件。 下面是我的登录脚本
if(isset($_POST['login'])){
$email = mysqli_real_escape_string($db , $_POST['email']);
$password = mysqli_real_escape_string($db , $_POST['password']);
$query = "select * from users where email='$email' and password='$password'";
$result = $db->query($query);
if($row = $result->fetch_assoc()){
if($row['status'] == 1){
$_SESSION['user_email'] = $email;
if(isset($_POST['remember_me'])){
setcookie("user_email" , $email , time()+60*5);
}
header("Location:myaccount.php");
exit();
}else {
header("Location:index.php?err=" . urlencode("The user account is not activated!"));
exit();
}
} else {
header("Location:index.php?err=" . urlencode("Wrong Email or Password!"));
exit();
}
}
用户登录后,他们会被重定向到此页面"myaccount.php
“
这仅显示用户电子邮件,我需要从表格中提取更多用户数据。
答案 0 :(得分:0)
您可以将任何数据设置为会话
像这样 $_SESSION['username'] = $row['username'] ;
$_SESSION['name'] = $row['name'] ;
$_SESSION['family'] = $row['family'] ;
所以
if (isset($_POST['login'])) {
$email = mysqli_real_escape_string($db, $_POST['email']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$query = "select * from users where email='$email' and password='$password'";
$result = $db - > query($query);
if ($row = $result - > fetch_assoc()) {
if ($row['status'] == 1) {
$_SESSION['user_email'] = $email;
$_SESSION['name'] = $row['name'];
$_SESSION['family'] = $row['family'];
if (isset($_POST['remember_me'])) {
setcookie("user_email", $email, time() + 60 * 5);
}
header("Location:myaccount.php");
exit();
} else {
header("Location:index.php?err=".urlencode("The user account is not activated!"));
exit();
}
} else {
header("Location:index.php?err=".urlencode("Wrong Email or Password!"));
exit();
}
}