Set a default value to an Input type Date

0

Good morning, I am working on a project using HTML5 and PHP, in this project I have the option to register people, in which they are asked for general information such as names, surnames, date of birth, etc., for the date of birth, use a input type Date to show me a calendar in the form, if it works, now I have another form in which I can update the information of the person has been registered, in that form all the previously entered data are loaded and placed in the textbox automatically, but I want the date to automatically appear in the input type date to register without having to put it back, any ideas?

I leave here my PHP code

  

echo "WORKS; /

$id = $_GET["id"];
$stmt = $mbd->prepare("CALL sp_getdataupdate(?)");
$stmt->bindparam(1, $id, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;    /* $fecha = $result['fecha_nacimiento'];
$fecha1 = split("/",$fecha);
$fechaf = $fecha1[0]."-".$fecha1[1]."-".$fecha1[2];
//$fechaf;
//var_dump($result); */ }

if (isset ($ _ POST ["update"])) {     / echo "WORKS; /     $ stmt = null;

$curp = $_POST["curp"];
$nombres = $_POST["nombres"];
$apellido_paterno  = $_POST["apellidop"];
$apellido_materno = $_POST["apellidom"];
$fecha_nacimiento = $_POST["nacimiento"];
$sexo = $_POST["sexo"];
$calle = $_POST["calle"];
$numero_exterior = $_POST["numex"];
$numero_interior = $_POST["numint"];
$codigo_postal = $_POST["cp"];
$colonia = $_POST["colonia"];
$estatus = $_POST["estatus"];
$delegacion = $_POST["delegacion"];
$id = $_POST["id"]; 
$stmt = $mbd->prepare("CALL sp_actualizarregistros(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bindparam(1, $curp, PDO::PARAM_STR);
$stmt->bindparam(2, $nombres, PDO::PARAM_STR);
$stmt->bindparam(3, $apellido_paterno, PDO::PARAM_STR);
$stmt->bindparam(4, $apellido_materno, PDO::PARAM_STR);
$stmt->bindparam(5, $fecha_nacimiento, PDO::PARAM_STR);
$stmt->bindparam(6, $sexo, PDO::PARAM_STR);
$stmt->bindparam(7, $calle, PDO::PARAM_STR);
$stmt->bindparam(8, $numero_exterior, PDO::PARAM_STR);
$stmt->bindparam(9, $numero_interior, PDO::PARAM_STR);
$stmt->bindparam(10, $codigo_postal, PDO::PARAM_STR);
$stmt->bindparam(11, $colonia, PDO::PARAM_STR);
$stmt->bindparam(12, $estatus, PDO::PARAM_STR);
$stmt->bindparam(13, $delegacion, PDO::PARAM_STR);
$stmt->bindparam(14, $id, PDO::PARAM_INT);

$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);

if (isset($result["Mensaje"])) {
    echo "ERROR AL REGISTRAR!";
}
else {
    echo "CORRECTO";
} } ?>
    
asked by Emanuel Mejia 31.10.2017 в 00:46
source

2 answers

1

To put a default value to an input type date, it must be in YYYY-mm-dd format, then when you load data from your database via php, the date may be disordered and with "/" instead of "-", for that you can place your input in the following way:

<input type="date" value="<?php echo date('Y-m-d', strtotime($valor['fecha'])) ?>">

In case you are using a class to generate a calendar with js or jquery (like datepicker), you should change the 'Y-m-d' to the format you need, for example: if it is '01 / 01/2000 'the format will be' d / m / Y ', if it is '01 -01-99 'the format will be' d-m-y ', etc. If your calendar also requires the time as '01 / 01/2000 01:00:00 ', the format will be:' d / m / YH: i: s', where H is for the hour, i for minutes and s for seconds. I hope it's helpful, greetings.

    
answered by 28.03.2018 в 01:04
0

You should use:

<input type="date" value="2017-11-31">

In the value, load the registration date with php, I suppose that when registering you have saved it in a database, no?

Example:

<input type="date" value="<?php echo $valor_database; ?>">
    
answered by 31.10.2017 в 00:52