[英]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.