简体   繁体   English

使用php登录时如何显示、编辑用户个人资料

[英]How to show, edit user profile when logged in with php

Please i want logged in user to be able to view and edit their previous details in a mysql database..here is my code so far请我希望登录用户能够在 mysql 数据库中查看和编辑他们以前的详细信息..这是我的代码

<?php session_start(); include 'dpconfig.php';

if (isset($_SESSION['uid'])) 
{
      echo $_SESSION['uid'];
}
else 
{
      echo "You are not Logged In!";  header("Location: header.php"); 
} 

$n = mysqli_query($conn,"Select * from user");
$run = mysqli_query($conn,"Select * from user"); 
$row = mysqli_fetch_array($run, MYSQLI_BOTH); 
{
    $showid = $row[0]; 
    $showfirst = $row[1]; 
    $showlast = $row[2]; 
    $showuid = $row[3]; 
    echo $showid; 
    echo $showfirst;
}
?>

Thanks谢谢

What you need to do when your user have log in you then need to have links in the dashboard to profile page then you need to have a query string in your link当您的用户登录时您需要做什么,然后您需要在仪表板中包含指向个人资料页面的链接,然后您需要在链接中包含一个查询字符串

eg例如

<?php 
session_start(); 
include 'dpconfig.php';

if (isset($_SESSION['uid'])) 
{
      echo $_SESSION['uid'];

      echo "<a href=\"profile.php?id=".$_SESSION['uid']."&action=view\">View Profile<a/>";
      echo "<a href=\"profile.php?id=".$_SESSION['uid']."&action=edit\">Edit Profile</a>";
}else{


    // not allowed redirect
}
?>

The above code is just a basic dashboard after the user have loggedin, we display to links to profile.php with two query string parameters, namely id we will use this to identify the current user, and action, this one will help us to know what action the user is doing(viewing/editing) their profile上面的代码只是用户登录后的一个基本仪表盘,我们用两个查询字符串参数显示到profile.php的链接,即id我们将使用它来识别当前用户,以及action,这将帮助我们知道用户正在做什么(查看/编辑)他们的个人资料

Then once they on any of the link, it will go to the profile.php page with url params.然后一旦他们打开任何链接,它就会转到带有 url 参数的 profile.php 页面。 then we use GET method to do our proccessing然后我们使用 GET 方法进行处理

Read about Get method here在此处阅读有关 Get 方法的信息

profile.php配置文件

<?php
    session_start();

  include 'dpconfig.php';

    if(isset($_GET['id']) && isset($_GET['action'])){

        if($_GET['action'] === "view"){


            // show user profile
        }


        if(isset($_GET['action']) ==="edit"):?>

        show html form with profile info to edit then process

        <?php

        endif;

    }else{

        // not allowed do something
    }




?>

Hope this will atleast point you to the correct direction.希望这至少会为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 HTML/PHP 中在更改密码表单上显示用户的个人资料图片(应显示已登录用户的图片) - How to Show Profile Picture of User on Change password form (Picture of Logged In user should be show) in HTML/PHP 在 profile.php 中显示登录用户的数据 - Show logged in user's data in profile.php 用户登录php时如何显示用户个人资料图片? - How to display a user profile pics while the user is logged in php? 用户使用cakephp登录时如何显示用户名? - how to show username when user is logged in with cakephp? 用户登录后如何显示他们的特定功能? - How to show user specific features when they are logged in? PHP的编辑配置文件,当用户不提供密码时,如何检查其是否为空 - php Edit Profile when user is not providing password how to check if its empty 如何通过PHP代码编辑Magento当前登录的用户详细信息 - How to edit Magento current logged user details via php code 使用Ajax编辑登录配置文件 - Edit the Logged In Profile with Ajax 如何隐藏导航栏链接选项并仅在用户登录 PHP 时显示该选项? - How to hide a navbar link option and only show the option when user is logged in in PHP? 如何在PHP中显示仅与登录用户相关的数据库中的数据 - How to show data from database only related to the logged in user in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM