I am making a page that looks for information in tables of a MySQL database, the connection is beautiful, but two errors are appearing:
Warning: mysqli_stmt :: bind_param (): Number of variables does not match number of parameters in prepared statement in ** / home / ---- / public_html / search.php on line 7
Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, object given in ** / home / ---- / public_html / search.php on line 15
My php code looks like this:
<?php
include ('conecta.php');
$pesquisa_rapida = $_POST["txtpesquisa"];
$sql=$mysqli->prepare("SELECT * FROM tabela WHERE nm_candidato LIKE '%".$pesquisa_rapida."%'");
$sql->bind_param("s",$pesquisa_rapida);
$sql->execute();
$sql->store_result();
$result=$sql->affected_rows;
if ($result > 0){
while($linha = mysqli_fetch_array($sql)){
$nm_candidato = $linha['nm_candidato'];
$nm_candidatura = $linha['nm_candidatura'];
$ds_cargo = $linha['ds_cargo'];
echo "<strong>Nome: </strong>".@$nm_candidato;
echo "<br /><br />";
echo "<strong>Nome Candidatura: </strong>".@$nm_candidatura;
echo "<br /><br />";
echo "<strong>Cargo: </strong>".@$ds_cargo;
echo "<br /><br />";
}
}
else {
echo "Desculpe, nada foi encontrado";
}
?>