NogDog;11002472 wrote:Sure, though you'll need a "rainy day" path in your logic to handle situations where the value in $_GET['page'] does not match anything in the DB. Also don't forget that you'll need to sanitize whatever value is received before using it in a query.
Okay this is what I have so far, will this work or not.
At the moment I get an error message saying "no database selected".
I have called the db - "mydb" and the table "url"
<?php
$localhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'mydb';
$connect = mysql_connect($localhost, $dbuser, $dbpass);
mysql_select_db('dbname', $connect);
$page = array('about','profiles','another_page');
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$sql = mysql_query("SELECT * FROM mydb WHERE id = '" . $page . "' LIMIT 1") or die (mysql_error());
if( mysql_num_rows($sql) ) {
$row = mysql_fetch_array($sql);
$title = $row['title']; // get title from database
$description = $row['description']; // get description from database
$keywords = substr($row['keywords'], 0, 250); // get keywords (250 characters) from database
} else {
$title = 'Set Default Title';
$description = 'Set Default Description';
$keywords = 'Set Default Keywords';
}
include($_SERVER['DOCUMENT_ROOT']. '/include/header.php');
include('content/'.$page.'.php');
include($_SERVER['DOCUMENT_ROOT']. "/include/footer.php");
?>
contents of my header.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $title?></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en">
<meta name="description" content="<?php echo $description?>">
<meta name="keywords" content="<?php echo $keywords?>">
</head>
<body>
<!-- HTML content goes here... -->
</body>
</html>