我在表单上有日期和时间显示,现在我的问题是如何
 我可以将日期和时间的值插入数据库,希望您能对我有所帮助。谢谢。

这是我的日期和时间代码:

<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>


更新了我的问题。

here is my form

error

最佳答案

如何将其存储在变量中。像这样的东西

<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);
}

?>

07-28 05:43