1
Hello,
I’m trying a problem with my query code in mysql, https://gist.github.com/Alkun/d2239eee1514a0dfc16a
If the user enters some value the search in the database is done normally, but if he leaves the form blank my isset() does not work. The message that appears is:
Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in C: wamp www bros result.php on line 17
<?php
include ("cabecalho.php");
include ("includes/conecta.php");
include ("includes/func.php");
?>
<?php
//Cria a variavel telefone enviada do formulario na pagina painel.php
$telefone = $_POST['telefone'];
//Verifica se o valor de telefone não é vazio.
if (!isset($telefone)) {
header("location: painel.php");
exit;
}
//Conecta com o banco e seleciona os arquivos para efetuar a contagem.
$con = mysqli_connect("localhost", "root", "", "pizzaria");
$query = mysqli_query($con, "SELECT nome, numero, endereco from clientes where telefone = $telefone");
$count = mysqli_num_rows($query);
//Se a contagem for 0
if ($count == 0) { ?>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
Ops! não encontramos nenhum cliente com este telefone,
<a href="painel.php" class="alert-link">tente novamente!</a>
</div>
<?php
die;
//Se a contagem for 1
} else {
if ($count == 1) { ?>
<div class="alert alert-success">
Encontramos 1 cliente com este telefone!
</div>
<?php
}
}
//Mostra todos os resultados encontrados.
while ($resultado = mysqli_fetch_assoc($query)) {
echo "Cliente: ". $resultado['nome']. "<br/>";
echo "Endereço: ".$resultado['endereco']. "<br/>";
echo "N°: ".$resultado['numero']. "<br/>";
}
?>
Change the
isset
forempty
.– rray
thanks for editing the post, I was unable to add in code format! Empty() function worked perfectly, thanks! but because isset() was not working?
– RFL