This question already has an answer here:
This isn't duplicated, since i've tried the search and nothin' i found out worked out for me. SPecially, this code seems to doesn't work with if/else.
i'm trying to search a car in my website, by the name of him in the database. But i'm getting 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
also, i don't know if i'm using the searchbox button right. I'm giving the action and the link to redirect as the same file, 'cause i think it is easier to put it all together, since it seems simple. Any help ? Here's the codes:
functions.php :
function buscarCarros($conexao, $nome){
$carro = array();
$conexao = mysqli_connect('mysql.hostinger.com.br','u374984363_ozzy','ozzy@123', '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'];
?>
and the 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">
<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>
</div>