#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    29
    Rep Power
    0

    Pre-populating HTML Date form input type


    Hi All,

    I wonder if you can help me, I'm trying to create a form that can be used to edit a database record. one field on which is a Date of Birth field, for which ideally i'd like to use the HTML "Date" input type. But, I'm having problems getting it to pre-populate with the date in the mysql record.

    Here's what's in the field i'm testing in the DOB column.....
    2006-06-01 00:00:00
    And here is the relevant lines from my PHP Script....

    PHP Code:
            <?php
            
    require_once('db_init.php');

            
    $conn mysql_connect(DBHOSTDBUSERDBPASS) or die('Could not connect to database server.');
            
    mysql_select_db(DBNAME) or die('Could not select database.');

            
    $UID mysql_real_escape_string($_POST["Horse_ID"]);
            
            
    $query "SELECT * FROM tblHorse WHERE Horse_ID =" $UID "";
            
            echo 
    "<br>";
            
    $result mysql_query($query) or die(mysql_error());

            if(
    mysql_num_rows($result)>=1){
        while(
    $row mysql_fetch_array($result)) {
            
    $IDNumber $row['Horse_ID'];
            
    $title $row['HorseName'];
            
    $forename $row['DateOfBirth'];
        }
    ?>
    Code:
                <td style="width:20%"><label for="forename">DateOfBirth:</label></td>
                <td style="width:20%"><input type="date" name="DateOfBirth" id="DateOfBirth" value="<?php echo($forename); ?>"></td>
    Any assistance would be most appreciated, I don't seem to get the date picker to display anything except dd/mm/yyyy on page loading.

    Many Thanks,
    Graham
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    100
    Rep Power
    50
    Don't you suppose that having the time as part of the value could mean that the browser doesn't consider it to be a date and therefor isn't populating the field with the value?

    Why is your DateOfBirth db field defined as a DATETIME data type?
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,810
    Rep Power
    4536
    Value should be yyyy-mm-dd.
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo