简体   繁体   中英

How do I get a specific user outputting their name once they logged in

Ok, I will elaborate but keep it simple. 1. Once User Registers, their information is stored into a database (already Completed) 2. Once User goes to login and successfully gets authorization to visit homepage. How do I output their first and last name.

I know this is php, but I am using PDO and php. Hopefully my code can help you help me. Thanks

//INSERT THE INFORMATION INTO THE DATABASE
      $query = "INSERT INTO stable (email, first_name, last_name, user_name, user_pass, re_password ) VALUES (:useremail, :firstname, :lastname, :username, :password, :repassword)"; 
      $result = $linkID->prepare($query);
      $result->execute(array(
          ':useremail' => $useremail,
          ':firstname' => $firstname,
          ':lastname' => $lastname,
          ':username' => $username,
          ':password' => $password,
          ':repassword' => $repassword
          ));

      //Displays an appropriate message
      if ($result) {
        // logged in
        header('Location: ../inc/home.php');
      };

Html:

<div id="div2" class="container">
    <div class="jumbotron text-center" style=" background-color:transparent ; position:relative; bottom:145px;">
        <p><?php <!--Can you please help me output name here--> ?></p>
    </div>
</div>

provided you are authorizing the user and session ID, and storing your variables correctly you can display their name with

<?php echo "Hello $firstname $lastname!";

edit You may want to wrap the above code in its own variable, that way you can do:

 if ($result) {
    // logged in
    header('Location: ../inc/home.php');
    $variablename = "Hello $firstname $lastname!"
  };

<div id="div2" class="container">
<div class="jumbotron text-center" style=" background-color:transparent ; position:relative; bottom:145px;">
    <p><?php echo "$variablename" ?></p>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM