Date Not Saving in Mysql from Php Registration Form

前端 未结 4 1370
别跟我提以往
别跟我提以往 2021-01-29 08:46

I am having trouble saving the date of birth in Mysql Db from Php registration form, what am I doing wrong?

  1. Check.php

    $month = $_POST[\'month\'];
4条回答
  •  -上瘾入骨i
    2021-01-29 08:54

    You should

    • fetch the correct POST-vars!!!!
    • use the dot sign for string concaternation
    • do a correct quotation
    • take care of cases in varnames ($day is not $Day)
    • dont put the unfiltered $_GET or $_POST vars into a query string
    • dont use mysql_ functions, they are deprecated

    this query should do what you want without errors:

    $month = $_POST['Birthday_Month']; 
    $day = $_POST['Birthday_day']; 
    $year = $_POST['Birthday_Year']; 
    
    $date = $year . "-" . $month . "-" . $day;
    
    $query = "INSERT INTO users (FirstName,LastName,Phone,DOB) VALUES ( '" . $FirstName . "','". $LastName . "','" . $Phone . "','" . $date . "')";
    
    mysql_query($query) or die(mysql_error());
    

    EDIT : I saw that you try to fetch the wrong POST-vars! You fetched $_POST['day'] but you need to fetch $_POST['Birthday_day'] which is the name of your select-field

提交回复
热议问题