我的表单上显示了日期和时间,现在我的问题是如何将日期和时间的值插入数据库,希望您能帮助我。谢谢。
这是我的日期和时间代码:
<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>
更新了我的问题。
这是我的表格
错误
1条答案
按热度按时间iyzzxitl1#
把它存储在一个变量里怎么样。像这样的