Jump to content

Template files - $template->loadTemplatefile and their interaction with PHP


cac1818

Recommended Posts

I am really new to PHP and trying to run through a book for learning the basics.  I am at a section where it is asking me to install PEAR (which I have done) and then it gets to creating template files.  There are a number of examples but the template files do not appear.  The screen is just blank.  I configured a form that accepts values into my database and then it is supposed to load another template file reporting what was just saved but after I click the "Submit" button, the template file is empty but the database has a valid entry. 

 

Any suggestions on the template file configuration?  Is there a PEAR package not working or not installed?

 

Any suggestions would be appreciated.  Thanks.

So I've entered the code in my .php file and in the .tpl file but nothing happens.  When I click submit, it doesn't redirect to the .tpl file, the URL string just adds on the name as in if I were adding a name and phone number it shows this upon Submit:

 

http://example/example.php?surname=Lincoln&firstname=Abraham&phone=+1144333030339

 

when the .php file asks it to load the .tpl file, it seems like it stops with the above URL instead of loading the template file with the information.

 

Here's the .tpl file:

 

<!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>

********************************

 

and here's the PHP file:

 

*********************************

<?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();

error_reporting(E_ALL);

ini_set('display_errors', 1);

}

else

header("Location: example8-1.html");

 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.