mysqli getting boolean [duplicate]

0

My site is not doing searches! I could not figure out how to do 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>
    
asked by anonymous 04.12.2014 / 23:30

1 answer

1

You are passing array $carros to the database table name field, I imagine you wanted to pass the variable $nome instead.

functions.php
Use prepared statements to prevent SQL injection attacks. Take a look at the discussion of the two issues, in a #

05.12.2014 / 00:58