Search existing records in the database [closed]

1

I would like to search for a client by ID in my database and to find it, show the code of the form here:

<form method="get" action="">
    <p align="center">Cedula :<input name="cedula" type="text" value="" 
    id="celcliente">
    <input name="consultar" type="submit" id="consultar" value="Revisar">
</form>

and here I have the PHP that I am using

<?php

if(isset($_GET["celcliente"]) &&
    !empty($_GET["celcliente"])){

    $cedula = $_GET["celcliente"];
    $query = "SELECT celcliente, idcliente, nombreCliente FROM cliente WHERE 
              idcliente LIKE '%$celcliente%' ORDER BY nombreCliente ASC";
    $ejecutar = mysql_query($query);
    $total_reg = mysql_num_rows($ejecutar);
    if($total_reg > 0){
        while($registros = mysql_fetch_array($ejecutar)){
            echo $registros['celcliente']."-";
            echo $registros['idcliente']."-";
            echo $registros['nombreCliente']."-";

        }
    }
    else{
        echo "No se encontraron resultados...!";
    }   
}

?>

The issue is that you can not find the data

    
asked by Andrex_11 12.03.2018 в 01:36
source

1 answer

1

Try changing these lines:

if(isset($_GET["celcliente"]) &&
  !empty($_GET["celcliente"])){

$cedula = $_GET["celcliente"];

POR:

if(isset($_GET["cedula"]) &&
  !empty($_GET["cedula"])){

$cedula = $_GET["cedula"];

Or else it just changes in your html

<input name="cedula" type="text" value="" id="celcliente">

POR:

<input name="celcliente" type="text" value="" id="celcliente">

Now I explain. When you create a form, the name attributes of each input, textarea, select are the keys of the $ _GET and $ _POST variables that you receive from the server side. In other words, if your text field is called a cedula, even if the id is id is celcliente in $ _GET you will only receive a cedula. If you want to do a test try to put a

exit(print_r($_GET));

At the beginning of your php file, and you'll see what I'm talking about.

    
answered by 12.03.2018 / 13:39
source