Search Record by php and mysql date

0

I have a bd of a newspaper which has a fairly large flow of articles which I want to filter by a specific date. the input is configured as date that same value I save it in a variable to make the query but it does not bring me the date that I specify in the input. Do you see any error in the code?

<html>
<head>
  <title>Busqueda</title>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>




<div class="row">
  <div class="col-md-4"></div>
  <div class="col-md-4">



    <center><h1>Buscador de Ediciones Antiguas</h1></center>
    <br></br>
    <form method="POST" action="registro.php" >
    <div class="form-group">
      <label for="doc">Fecha del Diario</label>
   <br></br>  
        <input type="text" value="" name="fechab" class="form-control" id="fechab" min="2004-11-19">
   <br></br>
    <center>
      <input type="submit" value="Consultar" class="btn btn-info" name="btn2">
      <input type="submit" value="Volver" class="btn btn-info" name="btnv">
    </center>

  </form>



  <?php



    if(isset($_POST['btn2']))

    {
      include("abrir_conexion.php");

        $fechab=($_POST['fechab']);
        if($fechab=="") 
          {echo "Ingrese una fecha";}
        else
        {  
          $resultados = mysqli_query($conexion,"SELECT fecha,titulo,textobreve,textolargo FROM $tabla_db1 WHERE fecha = $fechab");
            echo $fechab;
            while($consulta = mysqli_fetch_array($resultados))
          {
            echo 
            "
              <table width=\"100%\" border=\"1\">
                <tr>
                <td><b><center>fecha</center></b></td>
                </tr>
                <tr><td>".$consulta['fecha']."</td>
                </tr>
                <tr>
                  <td><b><center>titulo</center></b></td>
                </tr>
                <tr>
                  <td>".$consulta['titulo']."</td>
                </tr> 
                <tr>
                  <td><b><center>textocorto</center></b></td>
                </tr>
                <tr>
                 <td>".$consulta['textobreve']."</td>
                </tr>
                <tr>                
                  <td><b><center>textolargo</center></b></td>
                </tr>
                <tr>
                <td>".$consulta['textolargo']."</td>
                </tr>
              </table>
            ";
          }
        }

      include("cerrar_conexion.php");
    }
  ?>



  </div>
  <div class="col-md-4"></div>
</div>
    
asked by Roberto Cesar Mendoza Amarilla 23.12.2018 в 01:39
source

1 answer

0

start by changing:

<input type="text" value="" name="fechab"...

by:

<input type="date" name="fechab"...

then in the php you need some function that verifies if the date is valid and has the format that accepts mysql - > aaaa-mm-dd

    
answered by 23.12.2018 в 13:41