更新记录employee_id = $ id&&最后插入id mysqli

时间:2016-08-05 16:52:59

标签: php mysqli

我正在实施一个CMS,所以我有一个问题 如何更新mysqli中的最后一个插入记录 这是我的PHP代码

<?php

include 'dbconfig.php';
include 'session.php';

$id = $_GET['id'];
//echo $id; die;  
if (isset($_POST['logIn'])) {

    $timezone = new DateTimeZone("Asia/Kolkata");
    $date = new DateTime();
    $date->setTimezone($timezone);
    $time = $date->format(' H:i:s');

    $query = "INSERT INTO logindata (empId, logIn) VALUES ( '$id', '$time') "; // 
    $result = mysqli_query($dbconfig, $query);


    if ($result) {
        header("Location: https://google.com");
    }
} elseif (isset($_POST['logOut'])) {
    $timezone1 = new DateTimeZone("Asia/Kolkata");
    $date1 = new DateTime();
    $date1->setTimezone($timezone1);
    $time1 = $date1->format(' H:i:s');
// update record from here    
    $sql = "UPDATE logindata SET logOut='$time1' WHERE login_id = LAST_INSERT_ID() && empId = '$id'";
    $result1 = mysqli_query($dbconfig, $sql);

    if ($result1) {
        echo '<script type="text/javascript">
                  window.location = "http://facebook.com"
    </script>';
    }
}
?>

0 个答案:

没有答案