Error Undefined variable: mysqli_query

2

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

Code

<?php
    include ("db/conexion.php");

$query = "SELECT * FROM infraccion";

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

echo "hola";

?>

<!DOCTYPE html>
<html>
<head>
    <title></title>

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

                        <tr>    
                            <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>
                        </tr>

                        <?php } ?>
                    </tbody>
                </thead>
            </table>
        </center>
    </div>
</body>
</html>
    
asked by Jhonny 30.03.2017 в 20:05
source

2 answers

2

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
0

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