-
Apr 3rd, 2012, 07:19 AM
#1
Thread Starter
New Member
Dynamic CMS problem
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:
//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 "<ul><li><a href=' " . $row['id'] . " '> " . $row['page_title'] . "</a></li></ul>";
}
mysqli_close($conn);
?>
//default.php
<header>
<?php
require_once("header.php");
require_once("nav.php");
?>
</header>
<!-- +++++++++++++++++++++++ CONTENT +++++++++++++++++++++ -->
<div id="content">
<?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);
?>
</div>
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|