2
I’m making a page that searches for information in tables of a Mysql database, the connection is beautiful, but is showing two errors :
Warning: mysqli_stmt::bind_param(): Number of variables doesn’t 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";
}
?>
modified but now giving this error: Fatal error: Call to a Member Function bind_param() on a non-object in /home/irbpe586/public_html/search.php on line 7
– Sarah
@Sarah as you put? the error says that the query failed, table containing the call data
tabela
even?– rray
kkk q stupid, no! tidied the table name, but is giving another error : Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Object Given in /home/irbpe586/public_html/search.php on line 15
– Sarah
@Sarah you need to pass the connection as first argument in
mysqli_query()
– rray
$search_rapida = '%'. $_POST["txtpesquisa"] . '%'; $sql=$mysqli->prepare("SELECT * FROM resultado_votacao_candidato_zona_eleicaomunicipal WHERE nm_candidate LIKE ?");
– Sarah
as well, the connection to the database?
– Sarah
@Sarah yes, it should look something like this
mysqli_fetch_array($mysqli, $sql)
– rray
i put a include at the beginning that directs to a php q is making the connection to the database
– Sarah
@Sarah made a mistake
– rray
<?php

$host='host.com.br';
$user='user';
$pass='******';
$database='irbpe586_appirb';

$mysqli= new mysqli($host,$user,$pass,$database);

if (mysqli_connect_errno()){
 die ('Falha na conexao com o banco de dados. Erro: '.mysqli_connect_errno());
 exit();
}

?>
– Sarah
Let’s go continue this discussion in chat.
– Sarah
@Sarah corrected.
– rray
I put it like this but it didn’t work
– Sarah
while($line = mysqli_fetch_array($mysqli, $sql)){
– Sarah
ta giving this error: Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Object Given in /home/irbpe586/public_html/search.php on line 15
– Sarah
the error is in mysqli_fetch_array(), I did so: mysqli_fetch_array($mysqli, $sql)), but it did not work
– Sarah
@Sarah I switched the
strore_result
forget_result()
– rray
already got put like this: while ($dados= mysqli_fetch_array($result,MYSQLI_ASSOC)) {
– Sarah