无法将出生日期数据存储到数据库

时间:2013-09-02 07:27:04

标签: php

我试图将注册数据存储到数据库中,并且它在没有出生日期的情况下完美运行。当我把出生日期,它永远不会存储到数据库。会有什么问题?

这是示例代码

include('config.php');
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                $fname = mysql_real_escape_string($_POST['firstname']);
                $lname = mysql_real_escape_string($_POST['lastname']);
                $email = mysql_real_escape_string($_POST['email']);
                $dob = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
                mysql_real_escape_string($dob);
                $password = mysql_real_escape_string($_POST['password']);
                $mobilenumber = mysql_real_escape_string($_POST['mobilenumber']);
                $postalcode = mysql_real_escape_string($_POST['postalcode']);
            }
            if(isset($_POST['firstname'])){
            if(empty($fname)){
                echo '';
            }else{
            $success=("INSERT INTO customer (FName, LName, DoB, Email, Password, MobileNum, PostalCode) 
            VALUES ('$fname','$lname','$dob', '$email', '$password', '$mobilenumber','$postalcode')");
            mysql_query($success);
            Header("Location: ?");
            }
            }

1 个答案:

答案 0 :(得分:2)

尝试改变

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

$dob = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
$dob = date("Y-m-d", strtotime($dob));

希望有所帮助。