使用会话从表中提取更多数据(我想以配置文件格式显示用户的数据)

时间:2016-08-14 10:25:19

标签: php jquery mysql

登录后我很难显示用户的个人资料。我只能在会话中显示用户电子邮件。 下面是我的登录脚本

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

这仅显示用户电子邮件,我需要从表格中提取更多用户数据。

1 个答案:

答案 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();
    }
}