Error in while PHP

0

I have this while to show me some records of the database when I click a button but before that it appears that I have an error.

Code:

<?php
$conexion = mysqli_connect("localhost", "root", "","henkel");
$consulta ="SELECT DISTINCT*  FROM lote where Etapa=11   order by HoraFinal DESC limit 50";
$consulta2 ="SELECT DISTINCT * FROM lote where Etapa = 1 and Equipo = 2 ORDER BY HoraInicio DESC limit 20";

if ($conexion -> connect_errno){
    die("Fallo la conexion:(".$conexion -> mysqli_connect_errno().")".$conexion-> mysqli_connect_error());
}

if(ISSET($_POST['btnActualizar'])){         
    $resconexion= mysqli_query($conexion,$consulta);  
}      
?>    
<!doctype html>
<html lang="es">
    <form action ="Reportes.php" method ="post">
    <head>
        <title>Lotes</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">    
</head>    
    <body>    
<h2>Lotes terminados </h2>    
<table>    
    <?php
      while($cont1=mysqli_fetch_array($resconexion))   //////linea 70 ////////
          echo
        '<tr>'.
        '<th>'.$cont1['Lote'].'</th>'. 
          '<th>'.$cont1['IDH'].'</th>'.
          '<th>'.$cont1['NumOrden'].'</th>'.
          '<th>'.$cont1['Operador'].'</th>'.
          '<th>'.$cont1['Equipo'].'</th>'.
          '<th>'.$cont1['Etapa'].'</th>'.
          '<th>'.$cont1['HoraFinal'].'</th>'.
        '</tr>';
    ?>
</table>

    
asked by rolyx22 06.04.2018 в 20:14
source

1 answer

0

This error is common because nowhere in the PHP script validate that the request is of POST and not GET , the easiest way to do this is to validate the REQUEST_METHOD the $_SERVER is there where is the verb used for the request

if ($_SERVER['REQUEST_METHOD'] === 'POST'){ ... }

Your code might look like this

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
    $conexion = mysqli_connect("localhost", "root", "","henkel");
    $consulta ="SELECT DISTINCT*  FROM lote where Etapa=11   order by HoraFinal DESC limit 50";
    $consulta2 ="SELECT DISTINCT * FROM lote where Etapa = 1 and Equipo = 2 ORDER BY HoraInicio DESC limit 20";
    if ($conexion -> connect_errno){
        die("Fallo la conexion:(".$conexion -> mysqli_connect_errno().")".$conexion-> mysqli_connect_error());
    }
    if(isset($_POST['btnActualizar'])){
        $resconexion= mysqli_query($conexion,$consulta);
    }
}
?>

HTML

  <?php
  // si esta definida el resultado mostramos la tabla
  if(isset($resconexion)){
     echo "<h2>Lotes terminados </h2><table>";
     while($cont1=mysqli_fetch_array($resconexion)){
      echo    
        '<tr>'.
        '<th>'.$cont1['Lote'].'</th>'. 
        '<th>'.$cont1['IDH'].'</th>'.
        '<th>'.$cont1['NumOrden'].'</th>'.
        '<th>'.$cont1['Operador'].'</th>'.
        '<th>'.$cont1['Equipo'].'</th>'.
        '<th>'.$cont1['Etapa'].'</th>'.
        '<th>'.$cont1['HoraFinal'].'</th>'.
        '</tr>';
     }
    echo "</table>";
  }

?>
</table>
    
answered by 06.04.2018 / 20:59
source