- 我有一个带有日期字段的表单。
- 我用jquery datepicker选择一个日期。格式是mm/dd/yyyy。
- 日期插入数据库像0000-00-00。
- 当我使用die($ startdate);这会在取消注释时以正确的格式输出正确的日期。
DB类型:日期将mm/dd/yyy转换为mysql格式
代码:
$startdate = date('Y-m-d', strtotime($_POST['startdate']));
//die($startdate); //<--outputs the correct date in the correct format when uncommented.
try {
$stmt = $db->prepare('INSERT INTO table (firstname,lastname,startdate) VALUES (:firstname, :lastname, :startdate)');
$stmt->execute(array(
':firstname' => $_POST['firstname'],
':lastname' => $_POST['lastname'],
':startdate' => $_POST['startdate'],
));
}
我也试过
$startdate = date('Y-m-d', strtotime($_POST['startdate']));
在try {},但也不管用。
我在做什么错?
这是约翰孔德。我相信这是非常简单的,这是不同的,为什么它不是重复的。如果您没有注意到我的代码中存在“错误”。我需要帮助找到问题。马克发现它,现在它可以工作。我仍然想知道为什么这很难理解。
此问题已在stackoverflow上多次询问。请搜索它,你一定会找到你的答案。 –