gpt4 book ai didi

php - 仅显示登录用户数据

转载 作者:行者123 更新时间:2023-11-28 10:40:12 24 4
gpt4 key购买 nike

这是我的 setting.php 代码:

<?php session_start();
include 'conn.php';
include '../includes/layouts/header.php';
if(!isset($_SESSION['user']))
{
header("location:signin.php");
}
if(isset($_SESSION['update']))
{
echo $_SESSION['update'];
unset($_SESSION['update']);
}
$sql="SELECT * FROM signup";
$qry=mysql_query($sql);
$rows=mysql_fetch_array($qry);
?>

<div id="main">
<div id="navigation">
<div class="">
Welcome to LMS
<ul>
<li><a href="#"><?php echo $_SESSION['user']; ?></a>
<ul>
<li><a href="application.php">Send Leave Application</a></li>
<li><a href="setting.php">Setting</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
&nbsp;
</div>
<div id="page">


<form method="post" action="update.php">
<div class="reg_section">
<h3>Your Personal Information</h3>

<input type="text" name="fname" value="<?php echo $rows[1];?>" placeholder="First Name"><br>
<input type="text" name="lname" value="<?php echo $rows[2];?>" placeholder="Last Name"><br>
<input type="text" name="uname" value="<?php echo $rows[3];?>" placeholder="Desired Username"><br>
<input type="text" name="email" value="<?php echo $rows[4];?>" placeholder="Email"><br>
<input type="text" name="department" value="<?php echo $rows[5];?>" placeholder="Department"><br>
<input type="text" name="id" value="<?php echo $rows[6];?>" placeholder="Id #"/><br>
<input type="text" name="phone" value="<?php echo $rows[7];?>" placeholder="Phone #"/><br>

</div>
<div class="reg_section">
<h3>Your Password</h3>
<input type="password" name="pass" value="<?php echo $rows[8];?>" placeholder="Your Password"><br>
<input type="password" name="cpass" value="<?php echo $rows[8];?>" placeholder="Confirm Password">
</div>
<div class="reg_section">
<h3>Your Address</h3>
<input type="text" name="address" value="<?php echo $rows[9];?>" placeholder="Address">
</div>
<p class="submit"><input type="submit" name="submit" value="Update Info"></p>

</form>

</div>
</div>





<?php include '../includes/layouts/footer.php' ?>

这是 Update.php 代码:

<?php session_start();
include 'conn.php';
if(isset($_POST['submit']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$user=$_POST['uname'];
$email=$_POST['email'];
$depart=$_POST['department'];
$id=$_POST['id'];
$phone=$_POST['phone'];
$pass=$_POST['pass'];
$address=$_POST['address'];
$msg="Record Update Successfuly";
$qry="UPDATE signup SET First_Name='$fname',Last_Name='$lname',Username='$user',Email='$email',Department='$depart',Employe_Id='$id',Phone='$phone',Password='$pass',Address='$address' WHERE Username='$user'";

if(mysql_query($qry))
{

header('location:setting.php');
echo $_SESSION['update']=$msg;
}
else
{
echo mysql_error();
}
}
?>

现在,我希望只有登录用户才能更改他们的记录,并且表单应该包含他们自己的数据,但我做不到。当我登录页面时,它只会显示数据库的第一条记录,但我希望它只显示已登录的用户记录。我该怎么做?

……

最佳答案

当您应该考虑采用 mysqlipdo 时,我不会讨论使用 mysql

您正在选择查询中的所有记录。您只需要选择所需的一个。假设您正在设置用户在 session 中,您可以这样调用它。

例如:$sql="SELECT * FROM signup WHERE userId = '$_SESSION['userId']'";

关于php - 仅显示登录用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23167963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com