0

I've worked my way through this Youtube tutorial: https://www.youtube.com/watch?v=1YbbUS_SxSk&t=609s

..and for some reason, my data from my mySQL table is not printing at all within the table, though there appears to be the correct number of rows within the HTML table. Connection to MySQL and connection with the appropriate table seems to be working fine - the records are just not printing in the table.

> <html>
    <head>
        <title>Delete Records</title>
    </head>
    <body>
        <table border=1 cellpadding=1 cellspacing=1>
            <tr>
                <th>Image</th>
                <th>Delete</th>
            </tr>
            <?php
                //connect with mysql
                $con = mysqli_connect('localhost', 'root', '');
                if (!$con){
                    echo"Connection not established";
                }
                //select database
                mysqli_select_db($con, 'photos');

                //select query
                $sql = "SELECT * FROM images";
                if(!$sql){
                    echo"Table not selected";
                }

                //execute the query
                $records = mysqli_query($con, $sql);

                while (mysqli_fetch_array($records)){
                    echo "<tr>";
                    echo "<td>".$row['image']."</td>";
                    echo "<td><a href=delete.php?id=".$row['ID'].">Delete</a></td>";
                    echo "</tr>";
                }
            ?>
        </table>
    </body>
</html>

This is what the table ends up looking like: HTML Table

No data in the table!

2 Answers 2

2

Change this line

            while (mysqli_fetch_array($records)){

To

            while ($row = mysqli_fetch_array($records)){
Sign up to request clarification or add additional context in comments.

Comments

0

Simple error

 while ($row = mysqli_fetch_array($records))

This should be used to allow free flowing code

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.