Error Undefined variable: mysqli_query


I do not list my data in a table, I do not know if I'm failing to call the query.

The error is:

Error Undefined variable: mysqli_query


    include ("db/conexion.php");

$query = "SELECT * FROM infraccion";

$result =$conexionBD->query($query);

echo "hola";


<!DOCTYPE html>

    <div id="TablaMayor">   
        <center><img src="logo.png">
            <div id="titulo">
                <center><h1>Nombres, y valor de cada tipo de infraccion</h1></center>
                    <tr class="centro">
                        <td>Nombre Infraccion</td>
                        <?php while ($row=$result->mysqli_query()) { ?>

                            <td><?php echo $row['id'];?></td>
                            <td><?php  echo $row['nombre_infraccion'];?></td>
                            <td><?php  echo $row['fecha'];?></td>
                            <td><?php echo $row['valor'];?></td>

                        <?php } ?>
asked by Jhonny 30.03.2017 в 20:05

2 answers


You have a problem in $row = $result->mysqli_query() .

Your variable $result is an instance of mysqli_result , so that instruction is wrong because the method does not exist ( nor property) called mysqli_query() in class mysqli_result .

Instead, you should use, for example, mysqli_result::fetch_assoc() to get the next row of data:

<?php while ($row = $result->fetch_assoc()) { ?>

Also, as a tip, I recommend changing the lines in which you output data to the browser:

<?php  echo $row['nombre_infraccion'];?>

By the following:

<?= htmlspecialchars($row['nombre_infraccion']) ?>

In this way you will avoid any HTML / CSS / JS injection problem or display problems of strings that contain , > characters, HTML entities, etc.

answered by 31.03.2017 в 13:10

Your error is that you are mixing the interface of mysqli , that is, the line:

<?php while ($row=$result->mysqli_query()) { ?>

should be:

<?php while ($row=$result->fetch_assoc()) { ?>
answered by 31.03.2017 в 12:32