0
My site is not searching! I couldn’t figure out how to make queries through the search box, I try to access the cars in the database and it brings me the following error:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/u374984363/public_html/newcars/functions.php on line 61
my codes:
functions.php :
function buscarCarros($conexao, $nome){
    $carro = array();
    $conexao = mysqli_connect('mysql.hostinger.com.br','u374984363_ozzy','******', 'u374984363_ncars');
    $query = "select * from carros where nome = {$carro}";
    $resultado = mysqli_query($conexao, $query);
    while ($carros = mysqli_fetch_assoc($resultado)) {
        array_push($carro, $carros);
    }
    return $carro;
}
result_pesquisa.php :
<?php
include('menu.php');
include('conecta.php');
include('functions.php');
$carro = buscarCarros($conexao, $nome);
    foreach ($carro as $carros) :
        $carros['nome'];
?>
menu.php :
        <nav class="twelve columns">
        <ul class="menu">
            <li class="menu-item"><a href="index.php">Home</a></li>
            <li class="menu-item"><a href="comprar.php">Comprar</a></li>
            <li class="menu-item"><a href="">Vender</a></li>
            <li class="menu-item"><a href="">Contato</a></li>
        </ul>
        <form id="searchbox" action="result_pesquisa.php" method="POST">
            <input type="text" class="search-top remove-bottom" name="pesquisas" placeholder="Qual carro você procura?">
            <!-- <a href="javascript:document.getElementById('searchbox').submit();"> -->
            <a href="result_pesquisa.php"><span class="icon-top icon-search"></span></a>
        </form>
    </nav>
Place
var_dump($conexao->error);under themysqli_queryto see what the mistake was.– Thomas
Change your database password.
– Thomas
Changed ! Sorry for the error... I did the right thing and got this: string(40) "Unknown column 'Array' in 'Where clause'" Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in /home/u374984363/public_html/newcars/functions.php on line 62
– Gabriel
Change where it says
{$carro}for'{$nome}'in your query and see what happens.– Thomas
I got this: string(148) "You have an error in your SQL syntax; check the manual that Corresponds to your Mariadb server version for the right syntax to use near '' at line 1" Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in /home/u374984363/public_html/newcars/functions.php on line 62.. it seems that this code does not want to run :/
– Gabriel
Put the simple quotes also, as it is in the comment?
– Thomas
Now yes and he brought me this: string(0) ""... what happened ? he did not find what I searched ? by looking in the database, the name was Thank you !
– Gabriel
I’ll put it in the answer, you’ll see.
– Thomas
Okay! Thank you, I’ll be waiting !
– Gabriel