I want to display data gathered from a database in an html table using php and I'm having a problem by the name of:
Notice: Undefined index: filename in C:\Users\me\PhpstormProjects\untitled\page.php on line 39
I'm using PHP 7.4.26 + MySQL for database and I'm on Windows.
This is how the code looks:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
// Create database
$sql = "SELECT * FROM testdata";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$conn->close();
?>
<html>
<style>
table, th, td {
border: 1px solid black;
}
</style>
<body>
<table>
<tr>
<th>Filename</th>
<th>Size</th>
</tr>
<tr>
<td>
<?php echo $row["filename"] ?>
</td>
<td>
<?php echo $row["size"]; ?>
</td>
</tr>
</table>
</body>
</html>