0
I have a search form where the user type a number and if it is equal to the number in the database it returns the data of that number.
But when I click on button enviar
he shows me the page teste.php
with the following error (You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '232' at line 1) follows the code.
Database:
CREATE TABLE `tb_numeros` (
`numero` int(11) NOT NULL,
`funcionario` varchar(120) NOT NULL,
`rca` int(4) NOT NULL,
`regiao` varchar(14) NOT NULL,
`nchip` int(120) NOT NULL,
`imei` int(120) NOT NULL
) PRIMARY KEY (`numero`);
Form:
<form class="navbar-form navbar-left" method="post" action="teste.php" role="search">
<div class="form-group">
<input type="text" name="numerodigitado" class="form-control" placeholder="Buscar Número">
</div>
<button type="submit" name="enviar" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</form>
php test.:
<?php
include_once("../conn/conexao.php");//faz a conexao com o banco de dados
if(isset($_POST['numerodigitado'])){
$palavra = trim($_POST['numerodigitado']);
}else{
$palavra = trim($_GET['numerodigitado']);
}
if($palavra != NULL){
// Retorna apenas os registros PARECIDOS com 'palavra', limitando à 10 registros por página
$sql = "SELECT * FROM tb_numeros WHERE numero LIKE '%$palavra%' ";
}else{
// Retorna todos os registros do BD
$sql = "SELECT * FROM tb_numeros ORDER BY numero ";
}
$comparar = mysqli_query($conexao, $palavra) or die (mysqli_error($conexao));
if($comparar):
echo "<script>
alert('Número encontrado.');
</script>";
else:
echo "<script>
alert('Ocorreu um erro ao mostrar o número.');
</script>";
endif;
?>
But your PHP file does nothing at all. The only thing you do is set the value of
$palavra
and of$sql
, but you never run the query in the database and do not display any results on the screen. There was no missing onemysqli_query
to run the query and iterate on the results? If you have no idea what I said, it might be interesting for you to reread the documentation.– Woss
$compare = mysqli_query($connected, $word) or die (mysqli_error($connected)); I created this field and an if for $compare but it is showing a following error: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax
– Ferb
Then edit the question, enter the full code and the error message. This is essential information to verify the problem and should not be omitted.
– Woss
edited there friend
– Ferb
$compare = mysqli_query($connected, $sql) and not $word. This is the error...
– Rafael Mena Barreto