0
這是我的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>
</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();
}
}
?>
現在
,我想,只有登錄用戶可以改變他們的戰績和表單應該包含他們自己的數據,但我不能。 當我登錄到頁面時,它只會顯示數據庫的第一條記錄,但我希望它只顯示登錄的用戶記錄。 我該怎麼辦?
......
什麼是'$ sql =「SELECT * FROM註冊」;'?你爲什麼不在這裏使用where子句? – gaurav