簡単なクエリを使用してMySql
データベースに時間を送信しようとしています。これがコードです。localhost
PHP
HTML 側:
<form action = "Timecard.php"
method = "get">
<fieldset>
<label>Enter employee number:</label>
<input type = "text"
name = "EmployeeNumber" />
<button type = "submit" name = "submit" value = "ClockIn">
Clock In
</button>
<button type = "submit" name = "submit" value = "ClockOut">
Clock Out
</button>
</fieldset>
</form>
And the PHP:
<?php
require ("conn.php");
$filled = true;
$EmpNum = $_REQUEST["EmployeeNumber"];
if ($EmpNum == "") {
$filled = false;
}
if ($filled == false) {
print "Must enter a valid employee number to log in. Click <a href = 'http://localhost/Employee Timecard/Timecard.html'>HERE</a> to return to the login screen";
} else {
$timestamp = $_SERVER['REQUEST_TIME'];
$date = date('Y-m-d', $timestamp);
$time = sprintf(date('h-i-s', $timestamp));
print $timestamp . "<br>";
print $EmpNum . " has just logged ";
if (($SubmitButton = $_REQUEST["submit"]) == "ClockIn") {
print "in on " . $date . " at " . $time;
$query = sprintf("INSERT INTO timestamp(EmployeeNumber, Date, TimeIn, TimeOut) VALUES (".$EmpNum.",'".$date."','".$time."','')");
print $query;
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
print "checkpoint 2";
} else if (($SubmittButton = $_REQUEST["submit"]) == "ClockOut") {
print "out on " . $date . " at " . $time;
$query = sprintf("INSERT INTO timestamp(EmployeeNumber, Date, TimeIn, TimeOut) VALUES (".$EmpNum.",'".$date."','',".$time.")");
print $query;
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
print "checkpoint 2";
}
}
print "<br>checkpoint 3";
?>
データベースに送信すると、日付は問題なく送信されますが、時刻が正しくありません。-00:00:47
または00:00:05.
データベース内のフィールドのタイプが に設定されてい"time"
ます。なぜこれらの結果が得られるのでしょうか? シンプルである必要がありますが、それは私を夢中にさせています。