简体   繁体   中英

PHP form not displaying data

I recently posted today about my web form page not displaying data and we fixed that. I added like 15+ more forms to the page and updated the variables and everything and now there are no errors but when I hit the search button no data shows at all.

    <?php
$output = NULL;
if(isset($_POST['submit'])){
    // Connect to the database
    $mysqli = NEW MySQLi("localhost","root","","coprodeli");
    $nino_id = $mysqli->real_escape_string( $_POST['nino_id']);
    $nombre = $mysqli->real_escape_string( $_POST['nombre']);
    $apellidos = $mysqli->real_escape_string( $_POST['apellidos']);
    $sexo = $mysqli->real_escape_string( $_POST['sexo']);
    $estado = $mysqli->real_escape_string( $_POST['estado']);
    $fecha_de_nacimiento_desde = $mysqli->real_escape_string( $_POST['fecha_de_nacimiento_desde']);
    $fecha_de_nacimiento_hasta = $mysqli->real_escape_string( $_POST['fecha_de_nacimiento_hasta']);
    $tipo_de_centro = $mysqli->real_escape_string( $_POST['tipo_de_centro']);
    $nombre_del_centro = $mysqli->real_escape_string( $_POST['nombre_del_centro']);
    $region_del_centro = $mysqli->real_escape_string( $_POST['region_del_centro']);
    $nivel_de_estudio = $mysqli->real_escape_string( $_POST['nivel_de_estudio']);
    $entrada_desde = $mysqli->real_escape_string( $_POST['entrada_desde']);
    $entrada_hasta = $mysqli->real_escape_string( $_POST['entrada_hasta']);
    $egreso_desde = $mysqli->real_escape_string( $_POST['egreso_desde']);
    $egreso_hasta = $mysqli->real_escape_string( $_POST['egreso_hasta']);
    //Query the database
    $resultSet = $mysqli->query("SELECT nino_id, nombre, apellidos, sexo, estado, fecha_de_nacimiento_desde, fecha_de_nacimiento_hasta, tipo_de_centro, nombre_del_centro, region_del_centro, nivel_de_estudio,entrada_desde, entrada_hasta, egreso_desde, egreso_hasta FROM nino WHERE nino_id LIKE ('%$nino_id%') OR nombre LIKE ('%$nombre%') OR apellidos LIKE  ('%$apellidos%') OR sexo LIKE ('%$sexo%') OR estado LIKE ('%$estado%') OR fecha_de_nacimiento_desde LIKE ('%$fecha_de_nacimiento_desde%') OR fecha_de_nacimiento_hasta LIKE ('%$fecha_de_nacimiento_desde%') OR tipo_de_centro LIKE ('%$tipo_de_centro%') OR nombre_del_centro LIKE (%'$nombre_del_centro%') OR region_del_centro LIKE ('%$region_del_centro%') OR nivel_de_estudio LIKE ('%$nivel_de_estudio%') OR entrada_desde LIKE ('%$entrada_desde%') OR entrada_hasta LIKE ('%$entrada_hasta%') OR egreso_desde LIKE ('%$egreso_desde%') OR egreso_hasta LIKE (%'$egreso_desde%') ");
    if($resultSet['num_rows'] > 0) {
        while($rows = $resultSet->fetch_assoc())
        {
            $nino_id = $rows['nino_id'];
            $nombre = $rows['nombre'];
            $apellidos = $rows['apellidos'];
            $sexo = $rows['sexo'];
            $estado = $rows['estado'];
            $fecha_de_nacimiento_desde = $rows['fecha_de_nacimiento_desde'];
            $fecha_de_nacimiento_hasta = $rows['fecha_de_nacimiento_hasta'];
            $tipo_de_centro = $rows['tipo_de_centro'];
            $nombre_del_centro = $rows['nombre_del_centro'];
            $region_del_centro = $rows['region_del_centro'];
            $nivel_de_estudio = $rows['nivel_de_estudio'];
            $entrada_desde = $rows['entrada_desde'];
            $entrada_hasta = $rows['entrada_hasta'];
            $egreso_desde = $rows['egreso_desde'];
            $egreso_hasta = $rows['egreso_hasta'];
            $output .= "Estado: $estado<br />ID niño: $nino_id<br />Apellidos: $apellidos<br />Nombre: $nombre<br />Fecha Ingreso: $egreso_desde<br />Fecha Egreso: $egreso_hasta<br /> <br />";
        }
    }else{
        $output = "No results";
    }
}
?>
    <form method ="POST">
        ID niño: <input type="text" name="nino_id" />
        <br> </br>
        Nombre: <input type="text" name="nombre" />
        <br> </br>
        Apellidos: <input type="text" name="apellidos" />  <br> </br>
        Sexo: <input type="text" name="sexo" />  <br> </br>
        Estado: <input type="text" name="estado" />  <br> </br>
        Fecha de
        nacimiento desde
        (DD-MM-YYYY): <input type="text" name="fecha_de_nacimiento_desde" />  <br> </br>
        Fecha de
        nacimiento hasta
        (DD-MM-YYYY): <input type="text" name="fecha_de_nacimiento_hasta" />  <br> </br>
        Tipo de centro: <input type="text" name="tipo_de_centro" />  <br> </br>
        Nombre Del Centro: <input type="text" name="nombre_del_centro" />  <br> </br>
        Región del Centro: <input type="text" name="region_del_centro" />  <br> </br>
        Nivel de estudio: <input type="text" name="nivel_de_estudio" />  <br> </br>
        Entrada desde
        (DD-MM-YYYY): <input type="text" name="entrada_desde" />  <br> </br>
        Entrada hasta
        (DD-MM-YYYY): <input type="text" name="entrada_hasta" />  <br> </br>
        Egreso desde
        (DD-MM-YYYY): <input type="text" name="egreso_desde" />  <br> </br>
        Egreso hasta
        (DD-MM-YYYY): <input type="text" name="egreso_hasta" />  <br> </br>


        <input type="submit" name="submit" value="Search" />


       </form>
    <?php echo $output;?>

You can use this in your Query

http://php.net/manual/en/mysqli.error.php

I hope this helps

You need to localize the problem.

1) Test your sql query with minimum parameters. Copy your query and paste it in phpmyadmin or sqlYog or other sql management studio. Run your query and if it returns a valid result then go to the next step.

2) Check if you actually get inside of the if(isset($_POST['submit'])) statement. Just echo something inside the if statement.

3) If you're inside of the if(isset($_POST['submit'])) statement then try to echo all your post values like $_POST['nino_id'] and other to see if they are not empty.

4) If your post values are not empty theny try to echo the whole sql query on the page to see if this query is actually built correctly.

5) If the query is ok then check this if statement if($resultSet['num_rows'] > 0), the resultSet must not be empty. If it is empty, test the whole query (with all params) in the sql studio.

This way you can localize your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM