error in mysqli query

Asked

Viewed 847 times

2

Person, how I fix this my code, it is giving error:

<?php
//IMPRIME TODOS OS VALORES DO BANCO CADASTRO

$servidor = "localhost";
$usuario  = "root";
$senha    = "admin";
$banco    = "cadastro";

//conecta-se ao banco de dados Mysql
$con = new mysqli($servidor, $usuario, $senha, $banco) or die("<script     language='javascript'>alert('Unable to connect to database')</script>"); 

// Verifica se ocorreu algum erro
if (mysqli_connect_errno()) {
die('Não foi possível conectar-se ao banco de dados: ' . mysqli_connect_error());
exit();
}
if(isset($_POST['buscar'])){
$q = mysql_real_escape_string($_POST['consulta']);
$query_Busca = "SELECT * FROM 'equipamento' WHERE 'tombamento' LIKE '%$q%'";
$Busca = $con->query($query_Busca);
$row_Busca = mysqli_fetch_array($Busca);
$totalRows_Busca = $Busca->num_rows;

} else {
$query_Busca = "SELECT * FROM 'equipamento'";
$Busca = $con->query($query_Busca);
$row_Busca = mysqli_fetch_array($Busca);
if (!$check1_res) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
$totalRows_Busca = $Busca->num_rows;
}
?> 

The errors I get are: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given AND THIS: Undefined variable: check1_res in C: wamp www register query.php on line 58

  • Hello. Can you edit your question and add more details? What error does it make? Where does the error occur? Try to explain your problem better and don’t just paste the code.

1 answer

1


When making a query and table/field have special characters use:

`

Single quotes ' should only be used in text/Character values etc

change the occurrences:

$query_Busca = "SELECT * FROM 'equipamento'";

for:

$query_Busca = "SELECT * FROM `equipamento`";

or:

$query_Busca = "SELECT * FROM equipamento";

When executing a query remember to make it display database error like this:

$Busca = $con->query($query_Busca) or die($con->error);
  • Lost you is the guy! Sorry for the lack of details of the problem, but the little you gave me to solve cool. Now soh me answers one thing: how do I make the php search algorithm stay on another page Get called? I wanted to do this to make the database safer. You know how you do it? if you know edit in your reply and add please. I’m in need of this too and thanks for everything!

  • @Darkjontex, can create a separate file with functions and use a include/require to call them on another page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.