-4

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

这是示例代码

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: ?");
            }
            }
4

1 回答 1

2

尝试改变

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

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

希望它有所帮助。

于 2013-09-02T07:31:28.927 回答