无法在我的数据库中正确输入日期类型数据

j9per5c4  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(118)

每件事都得到正确输入,但日期正在提交到数据库像0000-00-00。请帮忙!!我试图呼应我的日期之前,张贴到dob和它出来是正确的,因为插入到表格。但当我检查我的数据库时,dob列集合更新为0000-00-00。
代码如下:

<?php
if (isset($_POST['submit'])) { 
    echo "<pre>";
    var_dump($_POST);
echo "</pre>";}
$username = $_POST['username'];
$password = $_POST['password'];
//$salary = $_POST['salary'];
 $birthdate =  $_POST['year'] . '-' . $_POST['month']. '-' .$_POST['day'];
 echo $birthdate."<br>";

if(!empty($username)){
	if(!empty($password)){
		if(!empty($birthdate)){
		$servername = "localhost";
$usernamei = "root";
$passwordi = "password";
$databasei = "regis";

// Create connection
$conn = new mysqli($servername, $usernamei, $passwordi, $databasei);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
else {
	 echo $birthdate;
	$sql = "INSERT INTO iocl (user_name, password,dob)
	values ('$username','$password','$birthdate')";
	if($conn->query($sql)){
		echo "new record is inserted sucess";
	}
	else{
		echo "error: ".$sql."<br>".$conn->error;
	}
	$conn->close();
}}}}

    ?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题