<?php
// 1. Connect to the database
$LINK mysqli_connect('127.0.0.1''tyrfl709''[q8OXd*BEbxW6bM4''tyrfl709');
if (!
$LINK) {
    die(
"Database connection error: " mysqli_connect_error());
}

// 2. Determine which page to show, default is 'welcome'
$page = isset($_GET['page']) ? $_GET['page'] : 'welcome';

// Basic sanitization to avoid directory traversal
$page str_replace(['..''/''\\'], ''$page);

// 3. Query the table "pages" for a row where "name" = $page
$query  "SELECT code FROM pages WHERE name = '$page' LIMIT 1";
$result mysqli_query($LINK$query);

$content '';
if (
$result && mysqli_num_rows($result) > 0) {
    
$row mysqli_fetch_assoc($result);
    
$content $row['code'];
} else {
    
// If no row found, show an error message
    
$content "<p>Page not found.</p>";
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Website</title>
</head>
<body>
    <!-- Navigation -->
    <nav>
        <a href="index.php?page=welcome">Welcome</a> |
        <a href="index.php?page=contact">Contact</a>
    </nav>

    <!-- Main Content -->
    <div id="main">
        <?php echo $content?>
    </div>
</body>
</html>