Learning PHP and MySQL. Made a short script that retrieves contents from the database, and populates it in a tag in my html header.
index.php:
<?php
$link = mysqli_connect('localhost', 'root', 'abdullah');
if (!$link) {
echo "Could not connect";
exit();
}
if (!mysqli_select_db($link, 'chitra')){
echo "Could not find database";
exit();
}
$query = 'SELECT * FROM photos;';
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_array($result)){
$categories[] = $row['category'];
}
include 'main.html';
?>
main.html:
<!DOCTYPE html>
<html>
<head>
<title>Chitra</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<header>
<div id="header_username">username</div>
<div id="header_cat">
<select>
<?php foreach ($categories as $category): ?>
<option><?php echo htmlspecialchars($category, ENT_QUOTES, 'UTF-8'); ?></option>
<?php endforeach; ?>
</select>
</div>
</header>
<main>
TODO
</main>
</body>
</html>
This code was initially working. I started working on the body for a while, until suddenly, it started returning me a blank white page. I removed my main content to start over from scratch, but it still give me the same result.
I put echo statemnts throughout the PHP file, everything is executing fine until right before the include statement. I checked my Apache, MySQL, PHP installations, checked that everything is up and running. Everything is. I can't figure out the issue.