簡體   English   中英

登錄后如何讓特定用戶輸出其名稱

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

好的,我會詳細說明,但保持簡單。 1.一旦用戶注冊,他們的信息就會存儲到數據庫中(已經完成)。2.一旦用戶登錄並成功獲得訪問首頁的授權。 如何輸出他們的名字和姓氏。

我知道這是php,但是我正在使用PDO和php。 希望我的代碼可以幫助您。 謝謝

//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>

如果您正在授權用戶和會話ID,並且正確存儲了變量,則可以使用

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

編輯您可能希望將上面的代碼包裝在自己的變量中,這樣您可以:

 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM