I'm writing code that is straight from a PHP coding book. In the examples, there are template files that are referenced both within the PEAR extensions and ones that I
create. In one of the examples, there's a
$template->loadTemplatefile("example8.3.tpl", true, true);
and when I click Submit on a form, it is supposed to bring up this template file with the information. But this is not working, there's nothing that shows up. The entry is in the database but the template file does not show up.
The code is the following:
<?php
require "db_login.php";
require_once "HTML/Template/ITX.php";
//echo( "GET Array: ");
//print_r($_GET);
if (!empty($_GET["surname"]) &&
!empty($_GET["firstname"]) &&
!empty($_GET["phone"]))
{
if (!($connection = @ mysql_connect("$db_host", "$db_username", "$db_password")))
die("Could not connect to the database.");
$surname = mysqlclean($_GET, "surname", 50, $connection);
$firstname = mysqlclean($_GET, "firstname", 50, $connection);
$phone = mysqlclean($_GET, "phone", 20, $connection);
if (!mysql_select_db("$db_database", $connection))
showerror();
$query = "INSERT INTO phonebook VALUES (NULL, '{$surname}', '{$firstname}', '{$phone}')";
//$query = "INSERT INTO phonebook VALUES (NULL, '" . $_GET['surname'] . "', '" . $GET['firstname'] . "', " . $_GET['phone'] . ")";
if (!(@mysql_query($query, $connection)))
showerror();
$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile("example8-3.tpl", true, true);
$template->setCurrentBlock();
$template->setVariable("SURNAME", $surname);
$template->setVariable("FIRSTNAME", $firstname);
$template->setVariable("PHONE", $phone);
$template->parseCurrentBlock();
$template->show();
}
else
header("Location: example8-1.html");
?>
and the template file is the following:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Added a Phonebook Entry</title>
</head>
<body>
<h1>Added a Phonebook Entry</h1>
<table>
<tr>
<td>Surname:
<td>{SURNAME}
</tr>
<tr>
<td>First Name:
<td>{FIRSTNAME}
</tr>
<tr>
<td>Phone number:
<td>{PHONE}
</tr>
</table>
</body>
</html>
Any help would be appreciated. Thanks.