我在表单上使用日期选择器,并以“2014年5月20日”格式选择日期
在表单处理中我试图修改它以保存正确的(Y m d)格式,但每次我保存它仍然在数据库中存储as 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");
}
?>
答案 0 :(得分:0)
更正$ start_date2日期字符串。
尝试:
date("Y-m-d", $timestamp);