<?php
require_once("dbconn.php");
require_once("phpFunctions.php");

$query = "SELECT username, message, created_at FROM chatdb ORDER BY created_at DESC";
$result = executeQuery($conn, $query);

if ($result === false) { 
    throw new Exception("Error executing query: " . $conn->error);
} 

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "<p><strong>" . htmlspecialchars($row["username"]) . ":</strong> " . htmlspecialchars($row["message"]) . " <small><i>" . $row["created_at"] . "</i></small></p>";
    }
} else {
    echo "No messages yet...";
}
?>