我希望在用户登录时获取用户的登录时间我不知道我是否将更新语法放在适当的位置?这是我的代码
<!DOCTYPE html>
<?php
session_start ();
unset ($_SESSION['username']);
?>
<html>
<style type="text/css">
body{
float: right;
padding-top: 150px;
padding-right: 200px;
}
form{
padding-top: 60px;
padding-left: 50px;
width: 300px;
}
#login_wrap{
background-color: #a1bdb8;
padding-top: 10px;
height: 300px;
width: 400px;
border-radius: 17px 17px 17px 17px;
-moz-border-radius: 17px 17px 17px 17px;
-webkit-border-radius: 17px 17px 17px 17px;
border: 0px solid #000000;
-webkit-box-shadow: 0px 0px 20px -1px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 20px -1px rgba(0,0,0,0.75);
box-shadow: 0px 0px 20px -1px rgba(0,0,0,0.75);
}
</style>
<head>
<link rel="shortcut icon" href="image/favicon.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.min.css">
</head>
<body>
<main id="login_wrap">
<div id="login">
<form name="login" role="form" method="post">
<input class="form-control" name="username" type="text" placeholder="Username" required><br>
<input class="form-control" name="password" type="password" placeholder="Password" required><br>
<button type="submit" class="btn btn-success" name="button">Log-in</button>
</form>
</div>
</main>
</body>
<?php
$conn = new mysqli('localhost','root',' ','dole_transac_system') or die ('connection error');
if(isset($_SESSION['username'])){
header('Location:check_maker.php');
}else{
}
if(isset($_POST['button'])){
$user = isset($_POST['username']) ? $_POST['username'] : '';
$pass = isset($_POST['password']) ? $_POST['password'] : '';
$query = mysqli_query($conn,"SELECT * FROM login_info WHERE username = '$user' and password = '$pass'");
$row = mysqli_num_rows($query);
if ($row == 1) {
date_default_timezone_set('Asia/Singapore');
$dateTime = date('Y-m-d');
$loginTime = mysqli_query($conn,"UPDATE login_info SET dateTime = '$dateTime' WHERE username = '$username'");
$_SESSION['username'] = $_POST['username'];
header('Location:check_maker.php');
}else{
echo "<br><font color='red'>Error</font>";
}
}
?>
<script type="text/javascript">
function submitForm() {
$("#login").reset();
return false;
}
</script>
</html>