SQL does not return any table data despite not giving errors

Asked

Viewed 30 times

1

Good morning, I want that in the following code SQL returns from the database the values "id_Admin", "username_Admin", "password_Admin", but does not return anything despite not giving any errors.

<?php 

    $servername = "localhost";
    $username = "root";
    $password = "";
    $db = "aeac";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $db);

    // Check connection
    if(mysqli_connect_errno()){
        die("connection failed: "
            . mysqli_connect_error()
            . " (" . mysqli_connect_errno()
            . ")");
    }

    //get results from database
    $result = mysqli_query($conn, "SELECT * FROM admin");

    echo "<table id='tableId' align='center' style='width:60%; height:5%'>
    <tr>
    <th>ID</th>
    <th>Nome</th>
    <th>Password</th>
    </tr>";

    while ($property = mysqli_fetch_array($result));
    {
        echo "<tr>";
        echo "<td onclick='redirect()'>" . $property['id_Admin'] . "</td>";
        echo "<td onclick='redirect()'>" . $property['username_Admin'] . "</td>";
        echo "<td onclick='redirect()'>" . $property['password_Admin'] . "</td>";
        echo "</tr>";

    }
    echo "</table>";

?>

I’ve done a lot of research and changed the code several times to see if something worked but nothing. I’m sure all the fields are the same as in the database.

Thank you in advance, Redcandy.

1 answer

0


I did a test here, using exactly your code and in fact did not return any error, but only managed to print the results according to the desired as follows:

while($property = mysqli_fetch_array($result,MYSQLI_ASSOC))

Or

while($property = mysqli_fetch_assoc($result))

This is the only way to generate an associative array to print the results.

mysqli_fetch_array() - see about result type

mysqli_fetch_assoc()

Browser other questions tagged

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