Dynamic CMS using PHP MySQL databases


#1

I am using PHP and MySQL to build a dynamic CMS. I am really new to this. I set up my SQL database with the following
web_pages
id page_title url content

These files have the following codes:

[php]//header.php

<?php //Variables for the database $host = 'localhost'; $username = '###########'; $password = '######'; $dbname = '###########'; ?>

//nav.php
$conn = mysqli_connect($host, $username, $password, $dbname) or die(‘Error connecting to MySQL server.’);

$sql = “SELECT id, page_title, url FROM web_pages;”;
$result = mysqli_query($conn, $sql) or die(‘Error querying database.’);

//loop through the page titles to populate the navigation bar
while ($row = mysqli_fetch_array($result)) {
$page_title = $row[‘page_title’];
$url = $row[‘url’];
echo "

  • <a href=’ " . $row[‘id’] . " '> " . $row[‘page_title’] . “
”;
}

mysqli_close($conn);

?>

//default.php

<?php require_once("header.php"); require_once("nav.php"); ?>
<?php $conn = mysqli_connect($host, $username, $password, $dbname) or die('Error connecting to MySQL server.');

$sql = “SELECT page_title, url, content FROM web_pages WHERE content = ‘$content’;”;
$result = mysqli_query($conn, $sql) or die(‘Error querying database.’);

while ($row = mysqli_fetch_array($result)) {
$id = $row[‘id’];
$page_title = $row[‘page_title’];
$url = $_GET[‘url’];
$content = $row[‘content’];
}

if(!isset($_GET[‘id’])) {

echo $row[‘content’];
}
else
echo “default.php”;
mysqli_close($conn);
?>

[/php]

Rather than the user click on the navigation and it directing to a new non-existant page I want the content from the database to show up in the content section of the default page.

PLEASE HELP!! I need to get this working by tonight!