Filter search does not work

1

I have a form that passes query data and an external PHP file called busca.php

My problem is that I do not get any php error to know the problem that it does not find the filter search. When I use the normal search it returns me all the values of the bank.

What's happening? Here is the program code, where q is to receive the consulta text field of a consulta.php file:

if(isset($_POST['buscar'])){
    $q = $con->real_escape_string($_POST['consulta']);
    $query_Busca = "SELECT * FROM equipamento WHERE tombamento LIKE '%$q%'";
    $Busca = mysqli_query($con,$query_Busca) or die($con->error);
    // Check results
    if($Busca){
        //Se for um sucesso!
        $row_Busca = mysqli_fetch_assoc($Busca);
        $totalRows_Busca = $Busca->num_rows;
    }

In this else the function is working normal giving all the data of the bank as I wish the problem is even in the code above where I want to find the equipment only by the number of tipping that is in "consultation" yet he does not think and not me returns error.

} else {
    $query = "SELECT * FROM equipamento";
    $Busca = $con->query($query) or die($con->error);
    $row_Busca = mysqli_fetch_assoc($Busca);
    $totalRows_Busca = $Busca->num_rows;
}
    
asked by anonymous 04.08.2014 / 20:24

1 answer

1

Try to standardize your code, because in one part you use mysqli_ functions and in another you use objects, and those details end up causing a headache and difficulties in finding the problems.

copying from the working block would look like this:

(note: if the tipping field is int, use (int) to convert to integer instead of like.)

if(isset($_POST['buscar'])){
    $q = $con->real_escape_string($_POST['consulta']);
    $query = "SELECT * FROM equipamento WHERE tombamento = '" . (int)$q . "'";
    $Busca = $con->query($query) or die($con->error);
    // Check results
    if($Busca){
        //Se for um sucesso!
        $row_Busca = mysqli_fetch_assoc($Busca);
        $totalRows_Busca = $Busca->num_rows;
    }
    
04.08.2014 / 21:42