在数据库-000-00-00 00:00:00中是这样的


is such in the database - 0000-00-00 00:00:00

这使得我很难将2个输入放在一起,然后再将其放入数据库

问题是当数据库看起来像这样时0000-00-00 00:00:00

这就是我选择将日期和时间分开以使其尽可能简单的方式。

function tilmeldAdmin()
{
    if ($stmt = $this->mysqli->prepare('INSERT INTO `tilmeldt` (`title`, `info`, `Dato`,  `antal`, `opret_navn`, `opret_email`, `opret_id`) VALUES (?, ?, ?, ?, ?, ?, ?)')) { 
        $stmt->bind_param('sssissi', $title, $info, $Dato, $antal, $opret_navn, $opret_email, $opret_id);
        $title = $_POST["title"];
        $info = $_POST["info"];
        $Dato = $_POST["dob"] . $_POST["time"];//Here is error when it should be entered into the database (Everything else works just fine with no problems)
        $antal = $_POST["antal"];
        $opret_navn = $_SESSION["navn"];
        $opret_email = $_SESSION["mail"];
        $opret_id = $_SESSION["id"];
        $stmt->execute();
        $stmt->close();
    }
}

假设您获得的日期为YYYY-mm-dd格式,时间为HH:ii:ss,那么您的问题是在两个元素之间缺少一个空格。

$Dato = $_POST["dob"] .' '. $_POST["time"];

如果以相对合理的方式向您提供日期,您可以使用strtotime以您想要的格式获取日期。

$Dato = date("Y-m-d H:i:s", strtotime($_POST["dob"]." ".$_POST["time"]));