Problem with PHP Searcher

-3

GOOD LATE GALERY

I'm developing a site for a client and he wants to put a finder, in case he put the person's name and his burial place.

I just did the php code and the database, but when I do the test, the result appears blank.

appears like this to me:

Cemiterio Municipal Parque Águas Lindas
Localizador de Jazigos
Resultado da Pesquisa:
Resultado da Pesquisa:
Resultado da Pesquisa:
Resultado da Pesquisa:
Resultado da Pesquisa:

and in case it was to look like this:

Cemiterio Municipal Parque Águas Lindas
Localizador de Jazigos
Resultado da Pesquisa:maria claudia
Resultado da Pesquisa:maria cunha
Resultado da Pesquisa:maria lina
Resultado da Pesquisa:maria da luz
Resultado da Pesquisa:maria costa

the form code and the one I made:

<h1><center>Cemiterio Municipal Parque Águas Lindas</center></h1>
<h1><center>Localizador de Jazigos</center></h1>

<form method="POST" action="pesquisar.php">
    <center> Pesquisar:<input type="text" name="pesquisar" placeholder="Nome do Falecido">
    <input type="submit" value="ENVIAR"></center>
</form>

and the search code is this:

<h1><center>Cemiterio Municipal Parque Águas Lindas</center></h1>
<h1><center>Localizador de Jazigos</center></h1>
<?php
    $servidor = "localhost";
    $usuario = "root";
    $senha = "EU NAO POSTEI A SENHA";
    $database = "cemiterio";
    //Criar a conexao
    $conn = mysqli_connect($servidor, $usuario, $senha, $database);

    $pesquisar = $_POST['pesquisar'];
    $sql = "SELECT * FROM 'jazigos' WHERE 'NOME' LIKE '%$pesquisar%' LIMIT 5";
    $resultado_cemiterio = mysqli_query ($conn,$sql);

    while($rows_sql = mysqli_fetch_array($resultado_cemiterio)){
        echo "Resultado da Pesquisa:" ."<br>";
    }
?>

I NEED A LOT OF HELP WITH THIS PROJECT

And taking advantage, I need the result to present all the information of the searched name line (the table has 8 columns) type search "maria lima" so it looks like this:

mome :maria lina Data de nascimento: 10/10/190  idade: 80 anos 
 Data de falecimento: 01/10/2018 Quadra: 03 Jazigo: 1250 Gaveta: 03 

I do not know what else to do, I did a lot of research, but I did not find a solution.

This thank you for your attention and collaboration.

    
asked by anonymous 14.11.2018 / 18:40

2 answers

-1

In case you are really able to do the research and it is returning the results, what is missing is you display them. Inside the while loop replace it:

 while($rows_sql = mysqli_fetch_array($resultado_cemiterio, MYSQLI_ASSOC)){
        echo "Resultado da Pesquisa:". $rows_sql["nome_da_coluna_da_sua_tabela"]  ."<br>";
    }

Change the query to this:

 $sql = "SELECT * FROM 'jazigos' WHERE 'NOME' LIKE '%{$pesquisar}%' LIMIT 5";

You are forgetting to display the result through the indexes of your table in array returned

    
14.11.2018 / 18:54
-1

Your result is blank because you are not writing data in echo

while ($rows_sql = mysqli_fetch_array($resultado_cemiterio)) {
    //Aqui você escrever apenas um HTML fixo, não tem os dados do banco
    echo "Resultado da Pesquisa:" ."<br>";
}

What you want is something like this:

echo "Resultado da Pesquisa:<br>";
while ($rows_sql = mysqli_fetch_array($resultado_cemiterio)) {
    echo implode(", ", $rows_sql)."<br>";
}

In this simple example I just put the result columns together with a comma but you can sort as you like by picking up each column separately through the indexes, at a documentation of mysqli_fetch_array

Note:

  • The way your code looks is vulnerable to SQL Injection
  • If a pesquisar variable is not sent by the body of the request, the code will break, something like $pesquisar = isset($_POST['pesquisar']) ? $_POST['pesquisar']; : '' or $pesquisar = $_POST['pesquisar']; ?? '' (PHP 7)
14.11.2018 / 18:54