So I did it exactly like this tutorial showed...
But I get an error:
Parse error: parse error, unexpected T_VARIABLE in ../Docs/test/php/template.php on line 7
Fatal error: Call to undefined function: pageheader() in ../Docs/test/php/index.php on line 22
WHAT DID I MISS?
Here's the text of what I'm using...
TEMPLATE DB:
[php_man]# phpMyAdmin MySQL-Dump
# version 2.4.0
# http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
# Generation Time: May 20, 2004 at 06:13 PM
# Server version: 4.0.16
# PHP Version: 4.2.4-dev
# Database : `template`
# --------------------------------------------------------
#
# Table structure for table `templates`
#
CREATE TABLE templates (
templateid int(10) NOT NULL auto_increment,
name varchar(30) NOT NULL default '',
content text NOT NULL,
PRIMARY KEY (templateid)
) TYPE=MyISAM;
#
# Dumping data for table `templates`
#
INSERT INTO templates VALUES (1, 'page_header', '<!DOCTYPE HTML PUBLIC "−//W3C//DTD HTML 4.01\nTransitional//EN">rn<html>rn<head>rn\n<title>$pageTitle</title>rn</head>rn<body>');
INSERT INTO templates VALUES (2, 'page_footer', '</body>rn</html>');
[/php_man]
TEMPLATE.PHP
Code: Select all
<?php
function fetchTemplate ($templateName) {
$Query = "select content from templates where
name='$templateName'";
$tRes = mysql_query($Query);
$Template = mysql_fetch_array($tRes);
$Content = "echo "$Template[content]";";
return $Content;
}
function pageHeader($Title) {
eval (fetchTemplate("page_header"));
}
function pageFooter() {
eval (fetchTemplate("page_footer"));
}
?>INDEX.PHP
Code: Select all
<?php
// Simple Templating Engine
// using a database tutorial.
// Written by Matt Eunson
// Define database variables you have to change these
$Server = "localhost";
$Username = "***";
$Pass = "****";
$Database = "template";
// Now connect to the database
mysql_connect($Server, $Username, $Pass) or
die("Couldn't connect to database.");
mysql_selectdb($Database) or die("Couldn't select
database: $Database");
// Include the template functions
include_once "template.php";
// Start our page
$Title = "My Site";
pageHeader($Title);
// Some content here...
echo "Welcome to my site.";
// And close the page
pageFooter();
?>