[英]fetching id from login session and populating in home page : php and mysql
I have 'user' table which contains username and password details along with user_id which is primary key. 我有“用户”表,其中包含用户名和密码详细信息以及主键user_id。
user( user_id(pk) , username , password , address, email)
When I login to the website, I need to fetch the address and email id from the 'user' table based on the user_id of the username and populate it on home web page. 登录网站时,我需要根据用户名的user_id从“用户”表中获取地址和电子邮件ID,并将其填充在首页上。
Please can someone assist me on how to do this ? 请有人可以帮助我如何执行此操作吗?
Thank You. 谢谢。
while you validate the database with your user_id & password then set : 当您使用user_id和密码验证数据库时,请设置:
##index.php
$username=$_Post['valuefromform'];
$password=$_Post['valuefromform'];
$result_set="SELECT * FROM user";
$num_rows=mysql_num_rows($result_set);
if($num_rows!=0)
{
$result=mysql_fetch_array($result_set);
if($username==$result['username'] && $password=$result['password'])
{
$id=$result['user_id'];
$_SESSION['id']=$id;
header("location:index.php?uid=$id");
}
}
You can use get
method to get the value of userid
. 您可以使用get
方法获取userid
的值。
##home.php
$getid=$_GET['uid'];
echo $getid;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.