Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将当前日期插入数据库?_Javascript_Php_Jquery_Html_Css - Fatal编程技术网

Javascript 如何将当前日期插入数据库?

Javascript 如何将当前日期插入数据库?,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,代码: 使用现在()或当前时间戳() 或 创建表格时,您可以使用当前\u日期字段类型作为当前\u时间戳以便将当前日期和时间自动插入到列中 试试上面的代码: $enqq = "insert into enquires2(name,email,phone,message,current_date)values('$name','$email','$phone','$message',CURRENT_TIMESTAMP())"; 或者使用MYSQL的CURDATE()函数,它打印的日期与php

代码:

使用现在()当前时间戳()

创建表格时,您可以使用当前\u日期字段类型作为当前\u时间戳以便将当前日期和时间自动插入到列中

试试上面的代码:

  $enqq =  "insert into enquires2(name,email,phone,message,current_date)values('$name','$email','$phone','$message',CURRENT_TIMESTAMP())";
或者使用MYSQL的CURDATE()函数,它打印的日期与php的函数相同,更简单:

例如:


ennq=“在查询中插入2(姓名、电子邮件、电话、消息、当前_日期)值(““$name.”、“$email.”、“$phone.”、“$message.”、CURDATE())”

当前日期的类型是什么<代码>日期时间
时间戳
日期
?您可以在sql查询中使用当前\u时间戳或NOW()。当前\u日期类型为Date@samorten
$date=date('Y-m-d')
在查询中使用此
$date
<form method="post" action = 'index.php' onsubmit="return validateForm();" name="form">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" id="name" placeholder="Full Name" name="name" style="width: 74%; background: black;">
      </div>

      <div class="form-group has-feedback">
        <input type="email" class="form-control" id="email" placeholder="Email Id" name="email" style="width: 74%; background: black;">
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" id="phone" placeholder="Phone" name="phone" style="width: 74%; background: black;">
      </div>

      <div class="form-group has-feedback">
        <textarea rows="4" cols="39" name="message" placeholder="Message" style="background: black;"></textarea>
      </div>

      <div class="form-group has-feedback">
        <input name="captcha" type="text" placeholder="Put Text Here" style="margin-left: -100px; background: black;">
        <img src="captcha.php" style="margin-top: -7px;"/><br>
      </div>

      <input type="hidden" name="current_date" id="current_date"/>
      <script type="text/javascript">
      function getDate()
      {
          var today = new Date();
          var dd = today.getDate();
          var mm = today.getMonth()+1; //January is 0!
          var yyyy = today.getFullYear();
          if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
          today = yyyy+"-"+mm+"-"+dd;

          document.getElementById("current_date").value = today;
      }
      getDate();
      </script>

      <div class="form-group has-feedback">
        <input type="submit" name="enq" class="btn btn-success" value="Submit" style="margin-left: 215px; border-radius: 0px; margin-top: -80px;">
      </div>
</form>
$enqq =  "insert into enquires2(name,email,phone,message,current_date)values('$name','$email','$phone','$message',NOW())";
  $enqq =  "insert into enquires2(name,email,phone,message,current_date)values('$name','$email','$phone','$message',CURRENT_TIMESTAMP())";
$enqq =  "insert into enquires2(name,email,phone,message,current_date)
          values('$name','$email','$phone','$message','".date('Y-m-d')."')";