How to insert a data type DATE in mysql?

0

I have a problem inserting a data type date to mysql, melo inserted in the column as 000-00-00 This is my Form

       <div class="form-group">
       <label for="nombre">Fecha recibido</labe> <input type="date" name="fecha_rec" step="1" min="2013-01-01" max="2030-12-31" value="<?php echo date("Y-m-d");?>">
               </div>

My sentence to connect to the database is as follows

  <?php

  extract($_POST);  
 $server = "localhost";
              $usuario = "root";
             $contraseña = "";
             $bd = "bdpagina";

 $conexion = mysqli_connect($server, $usuario, $contraseña, $bd)
or die("error en la conexion");
$sentencia = "UPDATE contribuyente SET estado = '$estado', comentario = '$comentario', servicio = '$servicio' , fecha_rec ='$fecharec'WHERE contribuyente. id = '$id'";
//la variable  $mysqli viene de connect_db que lo traigo con el require("connect_db.php");
$resent=mysqli_query($conexion,$sentencia);
if ($resent==null) {
    echo "Error de procesamieno no se han actuaizado los datos";
    echo '<script>alert("ERROR EN PROCESAMIENTO NO SE ACTUALIZARON LOS DATOS")</script> ';
            echo "<script>location.href='usuario.php'</script>";
}else {


    echo "<script>location.href='usuario.php'</script>";

}
 ?>

    
asked by Daniela 22.05.2018 в 22:03
source

1 answer

0

in mysql to insert a date and recognize it as such you need to use when inserting a data (or modify it) a function: STR_TO_DATE('".$fecharec."','%Y-%m-%d') for the format that it seems you have in the table, but beware, you have to pass the date in php to the same format before.

    
answered by 23.05.2018 в 08:48