gpt4 book ai didi

php - 如何使用 PHP 将日期传递给 MySQL

转载 作者:行者123 更新时间:2023-11-29 13:26:18 25 4
gpt4 key购买 nike

我有一个包含此部分的 createAdmin.php 表单:

<p>Date of Birth:&nbsp; <input maxlength="4" size="4" type = "text" name = "year" value = "" placeholder="YYYY" > -
&nbsp; <input maxlength="2" size="2" type = "text" name = "month" value = "" placeholder="MM" > -
&nbsp; <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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com