Going from database to sessions

后端 未结 2 976
执念已碎
执念已碎 2021-01-29 15:17

Well I have my register done all nice, as required fields it holds your email, name, and password. When you log in it asks for your email and password.

When they log in

2条回答
  •  执笔经年
    2021-01-29 15:55

    When they log in and you are checking the login credentials (email and password), if you find the user, select their first name as well and store it in another session variable:

    $query = 'SELECT firstname FROM users WHERE email = $email AND password = $password LIMIT 1';
    ...
    if ($result && mysql_num_rows($result) == 1) {
        $row = mysql_fetch_object($result);
        $_SESSION['firstname'] = $row->firstname;
        ...
    

    That might not be exact based on table and column names, but that's the general idea.

提交回复
热议问题