我有一个包含此部分的 createAdmin.php 表单:
<p>Date of Birth: <input maxlength="4" size="4" type = "text" name = "year" value = "" placeholder="YYYY" > -
<input maxlength="2" size="2" type = "text" name = "month" value = "" placeholder="MM" > -
<input maxlength="2" size="2" type = "text" name = "day" value = "" placeholder="DD" >
缓存这些值:
$year = (int) $_POST['year'];
$month = (int) $_POST['month'];
$day = (int) $_POST['day'];
最后传递给 mySQL:
$formBirth = "{$year}{$month}{$day}";
$createAdmin = mysqli_query($db, "INSERT INTO admins (username, hashed_pwd, power, email, name, birth) VALUES (
'{$username}', '{$password}', '{$power}', '{$email}', '{$realName}', STR_TO_DATE('$formBirth', '%Y%m%d'))");
这个方法显然行不通。有什么想法吗?
最佳答案
尝试将所有这些放入一个变量中并使用它
$date = $year.'-'.$month.'-'.$day;
关于php - 如何使用 PHP 将日期传递给 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20092833/