简体   繁体   English

仅显示登录用户数据

[英]Show only login user data

This is my setting.php code: 这是我的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' ?>

and this is the Update.php code: 这是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();
    }
}
?>

now, I want that only logged-in users can change their record and the form should contain their own data, but I can't. 现在,我希望只有登录用户才能更改其记录,并且表单应包含自己的数据,但我不能。 When I log into the page then it will only show the first record of the database, but I want it to show only the logged-in user record. 当我登录页面时,它将仅显示数据库的第一条记录,但是我希望它仅显示已登录的用户记录。 How can I do it? 我该怎么做?

...... ......

I won't go into the discussion of using mysql when you should consider adoptiing mysqli or pdo . 当您考虑采用mysqlipdo时,我不会讨论使用mysql的问题。

You are selecting all records within you query. 您正在选择查询中的所有记录。 You only need to select the desired one. 您只需要选择所需的一个即可。 Assuming that you are setting the user is within the session you could call it like so. 假设您正在设置用户在会话中,则可以这样称呼它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM