【问题标题】:html input type datetime-local to datetime sql using phphtml 输入类型 datetime-local 到 datetime sql 使用 php
【发布时间】:2018-06-20 08:20:33
【问题描述】:

我在我的网页中创建了这个对象。

input type="datetime-local" name="datentime" size="15" style="height:30px; font-size:18px" placeholder="

现在我需要检索该值并将其放入我的 mysql 数据库中。我尝试了很多,但无法将值插入数据库。我的php代码如下。

$event_dnt = strtotime($_POST["datentime"]);

数据库存储为 YYYY-MM-DD HH:MM:SS

【问题讨论】:

  • 您显示的代码不会在表格中插入任何内容。它只是为变量赋值。显示您的代码,并显示表架构。

标签: php html mysql


【解决方案1】:

将日期从dd/mm/yyyy h:i(输入类型datetime-local格式的默认值)转换为Y-m-d H:i:s(Mysql格式)以保存在数据库中,使用以下代码:

date("Y-m-d H:i:s", strtotime($_POST["datentime"]))

【讨论】:

    【解决方案2】:

    您必须将时间戳时间(返回 strtotime 函数)转换为数据库格式字符串。

    例如,

    $_POST["datentime"] = '20.06.2018 10:12:45'; # OR '2018-06-08 10:12:45' -- just input sumulation
    $data = $_POST["datentime"];
    $dbInsertDate = date('Y-m-d H:i:s', strtotime($data));
    

    另外,通过正则表达式检查 $_POST["datentime"] 所需的格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 2020-12-23
      • 2020-01-16
      相关资源
      最近更新 更多