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
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 |
---|
CodePudding user response:
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.