0

The code does not have errors but now no data is coming out. This is my concern. The only thing I've done different from before was add columns of data that I wanted and added new variables as required.

    <?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;?>
  • 2
    adding a whole buch or error checks would help –  Sep 01 '15 at 23:07
  • There were no errors. The results just weren't displaying. – Anthony Sawah Sep 01 '15 at 23:08
  • Firstly, I believe $_POST is case sensitive (i.e. `$_POST['submit']` is different to `$_POST['SUBMIT']`). Even if it isn't, I'd still go for lower case only. Secondly it's worth writing a SQL query yourself and trying that via phpMyAdmin to ensure your query is syntactically correct, then if that works - there's an issue with the code itself. – ScottMcGready Sep 01 '15 at 23:09
  • I think it should be `$_POST['SUBMIT'];`? – aldrin27 Sep 01 '15 at 23:10
  • 1
    Hey, [you switched from mysql](http://stackoverflow.com/questions/32341329/im-not-seeing-any-results-from-my-web-page-when-i-query-my-form) to mysqli. Props! :) – kittykittybangbang Sep 01 '15 at 23:10
  • @kittykittybangbang but not using prepared statements... catch 22 – ScottMcGready Sep 01 '15 at 23:10
  • 1
    FYI what @Dagon was referring to was you should add checks to your code to ensure each branch is being followed. For example, after your `if(isset($_POST['submit'])){` you should do something like `echo "success";` to see if you are actually satisfying that criteria. (Rudimentary example of course, but it should be a quick and dirty check to see if that branch is being executed). – ScottMcGready Sep 01 '15 at 23:12
  • @ScottMcGready Hey, the guy just took a huge step in the right direction. Don't be such a Debbie Downer. :P – kittykittybangbang Sep 01 '15 at 23:13
  • @kittykittybangbang fair point ;) – ScottMcGready Sep 01 '15 at 23:13
  • Hey @ScottMcGready and aldrin27 you guys were right, that fixed something because now I'm receiving an error: Notice: Trying to get property of non-object in C:\wamp\www\search.php on line 13 – Anthony Sawah Sep 01 '15 at 23:15
  • YESSS I GOT IT I LOVE YOU ALL – Anthony Sawah Sep 01 '15 at 23:20
  • 1
    We love you too, @AnthonySawah. ...We love you too. – kittykittybangbang Sep 01 '15 at 23:25
  • You guys all saved kids in Peru btw, feel proud of yourselves. Except scott. he just spit on me. haha jk. – Anthony Sawah Sep 01 '15 at 23:26
  • I'm not even gonna ask about that... – ScottMcGready Sep 01 '15 at 23:28
  • Ok after I solved this problem, I added more columns of data that I wanted other than nino id and I'm not getting data back now :( Can someone help? – Anthony Sawah Sep 02 '15 at 01:23

1 Answers1

1

For the purposes of completeness, here's my take on what you should do.

Note that the $_POST['submit'] and <input type="submit... both are named submit in lower case.

<?php
$output = NULL;
if(isset($_POST['submit'])){
    // Connect to the database
    $mysqli = NEW MySQLi("localhost","root","","coprodeli");
    $search = $mysqli->real_escape_string( $_POST['search']);
    //Query the database
    $resultSet = $mysqli->query("SELECT ninoid FROM nino WHERE ninoid = '$search'");
    if($resultSet->num_rows > 0) {
        while($rows = $resultSet->fetch_assoc())
        {
            $ninoid = $rows['ninoid'];
            $output = "Nino ID: $ninoid";
        }
    }else{
        $output = "No results";
    }
}
?>
<form method ="POST">
        <input type="text" name="search" />
        <input type="submit" name="submit" value="Search" />
</form>
<?php echo $output;?>
ScottMcGready
  • 1,612
  • 2
  • 24
  • 33