【问题标题】:Date picker date not saving to database日期选择器日期未保存到数据库
【发布时间】:2014-07-09 06:14:16
【问题描述】:

我在表单上使用日期选择器,它选择格式为“2014 年 5 月 20 日”的日期

在表单处理中,我尝试修改它以保存为正确的 (Y m d) 格式,但每次我保存它时,它仍然在数据库中存储为 0000-00-00。不确定这个 WAS 之前发生了什么?

表单处理代码:

<?php
if (isset($_POST['submit'])) {

//Process the form
$project_title = mysql_prep($_POST["project_title"]);
$start_date = $_POST["start_date"];
$stage = $_POST["stage"];
$acc_manager = $_POST["acc_manager"];
$designer = $_POST["designer"];
$url = $_POST["url"];

$timestamp = strtotime($start_date);
$start_date2 = date("Y m d", $timestamp);

$query  = "INSERT INTO projects (";
$query .= " project_title, start_date, stage, acc_manager, designer, url";
$query .= " ) VALUES (";
$query .= " '{$project_title}', '{$start_date2}', '{$stage}', '{$acc_manager}', '{$designer}', '{$url}' ";
$query .= ")";

echo $query;

try { $result = mysqli_query($connection, $query);
} catch (Exception $e) {
    return 'Caught exception: '+  $e->getMessage()+ "\n";
}
//Test if there was a query error
if ($result) {
    //Success
    // would normally use a redirect ie redirect_to("somepage.php");
    //$message = "Subject created.";
    redirect_to("projects.php");
}else {
    //failure
    //$message = "Subject creation failed.";
    //redirect_to("add_project.php");
    echo $query;
}
} else {
// This is probably a GET request
redirect_to("add_project.php");
}
?>

【问题讨论】:

    标签: php forms mysqli datepicker


    【解决方案1】:

    正确的 $start_date2 日期字符串。

    试试:

    date("Y-m-d", $timestamp);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      相关资源
      最近更新 更多