Inserting a date from form into mysql server.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neilsy
    New Member
    • May 2015
    • 2

    #1

    Inserting a date from form into mysql server.

    I'm trying to insert date of birth from users into the MySQL database. However when I try to insert into the database it comes up with dateofbirth '0000-00-00'. The age function does work and it is just the date of birth field that won't function. It will still let me add the remaining fields. I tried $datetime1 as a way of using

    Code:
    $dateofbirth = $year .'-'. $month .'-'. $day;
    $date = date("Y-m-d");
    $datetime1 = date_create($dateofbirth);
    $datetime2 = date_create($date);
    $interval = date_diff($datetime1, $datetime2);
    $age = $interval->format('%y');
    
    $update = mysql_query("UPDATE users SET dateofbirth = '$dateofbirth', age = '$age' WHERE uid = '$uid'");
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    check what $dateofbirth’s value is to verify it’s a valid MySQL date.

    Comment

    Working...