Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, boolean given in C: \ xampp \ htdocs \ Projects_Php \ search_page.php on line 34

0

Good, waiting kindly for your help, I have this error, it has given me a headache, I have no idea how to solve it, here goes the code.

    Results page

$db_host = 'localhost';         
$db_nombre = 'registro';        
$db_usuario = 'sergio_roger';
$db_pass = 'sergio_roger';  
$buscar = $_GET['buscar']; $endl = '<br/>'; 

$conexion = mysqli_connect($db_host, $db_usuario, $db_pass, $db_nombre);

if(mysqli_connect_errno()) 
{
    echo 'Error al conectar a la base de datos ', $endl;
    exit();
}

mysqli_select_db($conexion, $db_nombre) or die ('No se encuentra la base de datos');

mysqli_set_charset($conexion, 'utf8');

$consulta = "SELECT * FROM producto WHERE nombre = $buscar";

$resultado =  mysqli_query($conexion, $consulta);

echo '<h2>Datos de la tabla producto </h2>';

while(($fila = mysqli_fetch_array($resultado, MYSQLI_ASSOC))){ //Linea de error

    echo '<table> <tr><td>';
    echo $fila['codigo'], '</td><td>' ;
    echo $fila['seccion'], '</td><td>';
    echo $fila['nombre'], '</td><td>';
    echo $fila['precio'], '</td><td>';
    echo $fila['origen'], '</td><td></tr></table>';
}

mysqli_close($conexion);

unset($endl);

? >

    
asked by Sergio Roger 29.09.2017 в 16:26
source

1 answer

0

When you get an error in that line means that the real error is in your query since it is not bringing any valid data, try to add $buscar in single quotes like this:

"SELECT * FROM producto WHERE nombre = '$buscar'";

If this does not work, check very well that the name of the table and the commune are copied exactly the same.

I hope you serve, greetings!

    
answered by 29.09.2017 / 16:30
source