我在表单上显示了日期和时间,现在我的问题是如何 我可以将日期和时间的值插入数据库,希望您能对我有所帮助。谢谢。
这是我的日期和时间代码:
<div class="row" style="margin-left:300px;">
<label>Date:</label>
<span id="date" name="calendar"></span>
</div>
<div class="row" style="margin-left:300px;">
<label>Time:</label>
<span id="clock" name="time"></span>
</div>
我的php代码:
<?php
include_once ('connection.php');
$calendar=$_POST["calendar"];
$calendar=date("Y-m-d",$calendar);
$time=$_POST["time"];
$time=date("h-i-s",$time);
$InsertSql = "INSERT INTO test2(date,timein) VALUES ('$calendar','$time')";
$res = mysqli_query($conn, $InsertSql);
?>
javascript表示日期和时间:
<script>
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var n = new Date();
var y = n.getFullYear();
var m = n.getMonth();
var d = n.getDate();
document.getElementById("date").innerHTML = months[m] + " " + d + " " + y;
</script>
<script>
(function () {
var clockElement = document.getElementById( "clock" );
function updateClock ( clock ) {
clock.innerHTML = new Date().toLocaleTimeString();
}
setInterval(function () {
updateClock( clockElement );
}, 1000);
}());
</script>
更新了我的问题。
答案 0 :(得分:0)
如何将其存储在变量中。像这样
<form action="" method="POST">
<button name="submit" class="submit">Send</button>
</form>
<?php
if(isset($_POST['submit']))
{
$calendar=date("Y-m-d");
$time=date("H:i:s");
$InsertSql = "INSERT INTO test2(date,timein) VALUES ('$calendar','$time')";
$res = mysqli_query($conn, $InsertSql);
}
?>