使用PHP选择更新的值

时间:2018-10-09 23:11:44

标签: php mysql

我正在基于登录和注销进行出勤,是否有办法使此代码正常工作,成功更新数据后出现问题,它将进入另一个记事本,并且在那里选择将显示用户图像和基本信息的查询。但是当我尝试注销时,它会显示不同的用户信息和图像。

这是我的php代码:

<?php
include_once ('connection.php');
if(isset($_POST['submit']))
{
$username2 = $_POST['username2'];
$password1= $_POST['password1'];
$time=date("H:i:s");
$sql = mysqli_query($conn,"SELECT tbl_visitor.Birthday,tbl_visitor.School_Company,tbl_visitor.Contact_number,tbl_visitor.Visitor_Address,tbl_visitor.image,tbl_visitor.Visitor_username,tbl_visitor.Visitor_id,tbl_visitor.Visitor_password,concat(Visitor_first_name,'',Visitor_last_name) as name,
    tbl_visitor_form.Time_in,tbl_visitor_form.Time_out , tbl_visitor_form.Number FROM  tbl_visitor LEFT JOIN tbl_visitor_form on tbl_visitor.Visitor_id = tbl_visitor_form.Visitor_id WHERE   tbl_visitor.Visitor_username = '$username2' and tbl_visitor.Visitor_password = '$password1' 
       order by Number DESC limit 1");

$count = mysqli_num_rows($sql);

if ($count == 0) {
$_SESSION['error_message'] = "Incorrect username or password";
header("Location:logout.php?");

} else{
      while ($row = mysqli_fetch_array($sql)) {
          $username2 = $row['Visitor_username'];
          $password1 = $row['Visitor_password'];
          $name=$row['name'];

           $id=$row['Visitor_id'];
            $image=$row['image'];




       if(empty($row['Time_in'])) {

                header("location:visitorvalidate1.php");

        } else if(empty($row['Time_out'])){  

          $InsertSql = "Update tbl_visitor_form set Time_out = '$time' where Visitor_username='$username2' and Visitor_password = '$password1' order by Number DESC limit 1 ";
          $res = mysqli_query($conn, $InsertSql); 
          header("location:outsuccess.php?");

        }else{
          header("location:visitorvalidate1.php");
             }
        }

    }
 }
?>

这是我的outsuccess.php:

 <?php 

include_once('connection.php');

$sql = "select  Visitor_username, image, Visitor_name  from tbl_visitor_form 
order by Number DESC limit 1 ";
$result = mysqli_query($conn,$sql);
while( $row = mysqli_fetch_array($result)) {

         $uname=$row['Visitor_username'];
         $name=$row['Visitor_name'];
         $image=$row['image'];

   }
?>

上面的第一个查询正在工作,但是select中的第二个查询有问题,它在更新后选择了不同的值。例如,当我尝试注销成功更新的user1时,有两个用户已经登录了user1和user2,但在outsuccess.php上却显示了user2的信息,而不是user1。希望您能帮助我解决此问题。预先感谢

0 个答案:

没有答案