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

时间:2018-07-03 11:52:14

标签: php mysql

每件事都得到正确的输入,但日期正被提交到诸如0000-00-00之类的数据库中。请帮忙!!我试图回显我的日期,然后再将其发布到dob中,出来的日期正确无误。但是,当我检查数据库时,dob列会得到一个带有Registers的更新。

代码如下:

<?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();
}}}}
	
    ?>

0 个答案:

没有答案