I am putting together a search page where in the HTML page a search button when clicked calls a Javascript function that passes the typed content to a php page. This page in PHP should connect to the database, fetch what was typed and return some values in a table, this table should be returned to the page in html (via javascript), and shown in a div with id="Resultado"
but it is giving an error:
Warning: mysqli_query (): (HY000 / 2008): MySQL client ran out of memory in /home/irbpe586/public_html/irbapp/testepesquisa/pesquisa.php on line 7 An error occurred in the query!
Please, if anyone can help me, I am very grateful.
Javascript within the html:
<script type="text/javascript">
$("#pesquisa_1").click(function() {
if($(this).val() != ""){
var rua = $('#pesquisa_rapida').val();
var urlmanual = "pesquisa.php";
$.post(urlmanual, {"pesquisa_rapida" : pesquisa_rapida} ,function(result) {
var div = document.getElementById("#Resultado");
div.innerHTML = result;
alert (result);
});
}});
</script>
HTML:
<input type="text" id="pesquisa_rapida" name="pesquisa_rapida" class="form-control item-formulario" placeholder="Pesquisa rápida..."/>
<button type="submit" id="pesquisa_1" name="opcao" value="1" class="btn botao1 item-formulario"><span class="glyphicon glyphicon-search"></span></button>
PHP:
<?php
if(isset($_POST['pesquisa_rapida'])){
$input = $_POST['pesquisa_rapida'];
@$con = mysqli_connect("host.com.br", "user", "******", "database");
if($con){
$query = mysqli_query($con, "SELECT * FROM 'resultado' WHERE nm_candidato LIKE '%$pesquisa_rapida%'");
if($query){
if(mysqli_num_rows($query) > 0){
//tabela
echo "<table border=1 cellspacing=0 align=center>";
echo "<tr bgcolor=#c0c0c0 style=color:white>";
echo " <td> UF do Estado </td>";
echo" <td> Nome do Municipio </td>";
echo" <td> Ano das Eleicoes </td>";
echo" <td> Nome do Candidato </td>";
echo" <td> Nome do Candidato na Urna </td>";
echo "</tr>";
while($result = mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>"; echo 'UF do Estado: '.$result['sg_uf'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Municipio: '.$result['nm_municipio'].'<br />'; echo "</td>";
echo "<td>"; echo 'Ano das Eleicoes: '.$result['dt_ano'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Candidato: '.$result['nm_candidato'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Candidato na Urna: '.$result['nm_candidatourna'].'<br />'; echo "</td>";
echo "</tr>";
}
}else{
echo 'Sem dados para essa busca!';
}
}else{
echo 'Ocorreu um erro na query!';
}
}else{
echo 'Ocorreu um erro na ligação à base de dados!';
}
}else{
echo 'Introduzir valor!';
}
?>