I am trying to search for the product title, but regardless of the title consulted, it always returns me the last record of the Product table.
I'm using the following code below to perform the search:
<?php
include "conexao.php";
$buscar = $_GET['buscar'];
$sql=$pdo->prepare("SELECT * FROM produto WHERE titulo LIKE '%".$buscar."%'");
$sql->execute();
foreach($sql->fetchAll() as $res){
echo'
<div id="prod" style="background-color:'.$res["fundosite_cor"].';width:33%; float:left; padding:10px 0;" class="center_prod_box">
<div align="center" id="titulo" style="width:100%;">
'.$res["titulo"].'
</div>
<div align="center" style="width:100%; height:130px; background-color:'.$res["fundosite_cor"].';">
<div align="center">
<a href="prod_detalhe_5.php?codigo='.$res["codigo"].'">
<img style="width:100%; max-width:100px;" src="img_produtos/'.$res["img01"].'" />
</a>
</div>
</div>
<div align="center" id="preco" style="width:100%;">
<span style="">R$ '.$res["preco"].'</span>
</div>
<div align="center" id="carrinho" style="width:100%;">
<a href="prod_carrinho.php?acao=add&codigo='.$res["codigo"].'">
<img style="width:100%; max-width:20px;" src="img/carrinho.png" title="Por no Carrinho" />
</a>
</div>
</div>
';
}?>
I would like to know how to get it to return the product related to the query made with the Title.