我在简单的$dob
表单输入和使用 PDO 将数据库插入到 datatype 的 mysql 表中时遇到了一些奇怪的问题date
。
输入表格(示例):
<select name="dob-month">
<option value="1">January</option>
</select>
<select name="dob-day">
<option value="01">1</option>
</select>
<select name="dob-year">
<option>2013</option>
</select>
PHP(基本):
$data = $_POST; //passed through mvc
$day = trim($data['dob-day']);
$month = trim($data['dob-month']);
$year = trim($data['dob-year']);
$birthdate = date('Y-m-d', strtotime($year."-".$month."-".$day));
$stmt = $this->core->dbh->prepare("INSERT INTO userinfo (birthdate) VALUES (:birthdate)");
$stmt->bindParam(':birthdate', $birthdate, PDO::PARAM_STR);
$stmt->execute();
但它给出了没有日期的日期?所以只是 2013-12 工作正常,但这一天总是-01?
它与日期的选择格式有关吗?