Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL to HTML Table, new

I can’t figure out why my code isn’t working? When i run it the page is blank!

This is a Harry Potter Database. I am trying to put the data within my SQL Database in a HTML Table. Sounds easy but I can’t figure out why my code is not working!

<!DOCTYPE html>
<html>
<head>
    <title> Harry Potter Database </table>
</head>
<body>
<table>
    <tr>
        <th> ID </th>
        <th> Name </th>
        <th> Age </th>
        <th> Website </th>
    </tr>
<?php
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); error_reporting(E_ALL); 
$conn = mysqli_connect("localhost", "root", "", "survey");
$sql = "SELECT * FROM result";
$res = $conn->query($sql);

if($res->num_rows > 0)
{
    while($row = $res->fetch_assoc())
    {
        echo "<tr>
        <td>". $row["ID"] . "</td>
        <td>". $row["Name"] . "</td>
        <td>". $row["Age"] . "</td>
        <td>". $row["Website"] . "</td>
        </tr>";
    }
}
else{
    echo "No RESULTS";
}
$conn->close();

?>
</table>
</body>
</html>

result is the name data within my database called survey

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Undefined array key "ID" in C:\xampp\htdocs\ws5\sqlquery.php on
line 26

This is the error in the source

Structure of Table

ID WEBSITE AGE WEBSITE

>Solution :

On Windows (where it looks like you are), MySQL stores all table and column names in lowercase by default (see the docs for "Identifier Case Sensitivity" and lower_case_table_names).

That means that instead of "ID", you should be using "id", instead of "Name" it should be "name", etc.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading