使用html5输入标记在mysql中插入日期

时间:2013-09-10 17:46:24

标签: php mysqli

<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="collect.php" method="post">
date:<input type="date" name="date"/><br/>
<input type="submit"/><br/>
</form>
</body>
</html>

此表格接受日期并将其发送至collect.php,如下所示

<?php
$connect=mysqli_connect("localhost","root","");
if(mysqli_connect_error()){
echo "Databse connect error";
die();
}
else echo "successfully connected <br/>";
$date=$_POST['date'];
$adddate="INSERT INTO `testform`.`date`(date) VALUES(".$date.")";
$result=mysqli_query($connect,$adddate);
if($result==TRUE)
    echo "date added asuccessfully";
else echo "problem in date";
?>

问题是它回声日期成功添加,但当我检查我的phpmyadmin结果是0000-00-00 我不明白这个原因。我几乎尝试了所有的事情。请帮助......

1 个答案:

答案 0 :(得分:1)

在日期附近添加引号

$date=mysqli_real_escape_string($connect,$_POST['date']);
$adddate="INSERT INTO `testform`.`date`(date) VALUES('".$date."')";
                                                     ^         ^