MYSQL日期字段始终输出0000-00-00 [英] MYSQL Date field always outputs 0000-00-00

查看:96
本文介绍了MYSQL日期字段始终输出0000-00-00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中的日期字段中插入生日时遇到了问题。
当我检查存储在数据库中的日期时,它总是返回0000-00-00。

I've got a problem with inserting a birthday to a Date field in my database. it always returns 0000-00-00 when i check the date that was stored in the database.

我使用以下代码:

$dob = date('Y-m-d', strtotime($_POST['registration_dob_year']."/".$_POST['registration_dob_month']."/".$_POST['registration_dob_day']));

我知道我的 $ _ POST ['registration_dob_year'] $ _ POST ['registration_dob_month'] $ _ POST ['registration_dob_day'] 变量是正确,因为如果我使用以下代码

I know for a fact that my $_POST['registration_dob_year'], $_POST['registration_dob_month'] and $_POST['registration_dob_day'] variables are correct, because if i use the following code

echo $dob;

它打印出类似 1986-01-07 在我的页面上。

It prints something like 1986-01-07 on my page.

推荐答案

为什么要使事情复杂化?只需使用:

Why are you complicating things? Just use:

$dob = $_POST['registration_dob_year']."-".$_POST['registration_dob_month']."-".$_POST['registration_dob_day'];

这篇关于MYSQL日期字段始终输出0000-00-00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆