Home >Backend Development >PHP Tutorial >PHP能将下拉列表的值赋给数据库中date类型的字段吗

PHP能将下拉列表的值赋给数据库中date类型的字段吗

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:51:29824browse

表单部分代码
************************************************省略**************************************
echo '年';
*******************************省略********************************************************
?>
表单验证部分代码
****************************************省略************************************************
if($_POST['year']!=请选择&&$_POST['month']!=请选择&&$_POST['day']!=请选择)
$birthday=$_POST['year'].$_POST['month'].$_POST['day'];
else array_push($errors,'请选择生日日期');
if(!empty($_POST['introduct'])) $introduction=$_POST['introduct'];
*******************************************省略*************************************************
?>
现在的问题是,我想将$birthday存到数据库data类型的字段下,可是传进去的值一直是0000-00-00,除非我把data类型换成字符型,刚学PHP,请大家帮忙啊


回复讨论(解决方案)

用时间戳保存,把时间类型改成int型吧。存进去的时候如下

$date=stetotime($birthday);

用时间戳保存,把时间类型改成int型吧。存进去的时候如下

$date=stetotime($birthday);


$date=strtotime($birthday);
打错。

$birthday=$_POST['year'] .'-'.$_POST['month'] .'-'.$_POST['day'];

@xuzuning,原来还可以这样,比1楼简单啊,不过,你的方法也挺好的@XXOOme,谢谢大家的帮助!!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn