从登录会话中获取 ID 并填充到主页中:php 和 mysql
fetching id from login session and populating in home page : php and mysql
我有 'user' table 其中包含用户名和密码详细信息以及 user_id 这是主键。
user( user_id(pk) , username , password , address, email)
当我登录该网站时,我需要根据用户名的 user_id 从 'user' table 中获取地址和电子邮件 ID,并将其填充到主页上页。
有人可以帮助我如何做到这一点吗?
谢谢。
当您使用 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");
}
}
您可以使用get
方法获取userid
的值。
##home.php
$getid=$_GET['uid'];
echo $getid;
我有 'user' table 其中包含用户名和密码详细信息以及 user_id 这是主键。
user( user_id(pk) , username , password , address, email)
当我登录该网站时,我需要根据用户名的 user_id 从 'user' table 中获取地址和电子邮件 ID,并将其填充到主页上页。
有人可以帮助我如何做到这一点吗?
谢谢。
当您使用 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");
}
}
您可以使用get
方法获取userid
的值。
##home.php
$getid=$_GET['uid'];
echo $getid;