Skip to Main Content
Learning PHP, MySQL, and JavaScript
book

Learning PHP, MySQL, and JavaScript

by Robin Nixon
July 2009
Beginner content levelBeginner
526 pages
14h 24m
English
O'Reilly Media, Inc.
Content preview from Learning PHP, MySQL, and JavaScript

A Practical Example

Let’s take the program sqltest.php from Example 10-8 in Chapter 10 and rewrite it to use Smarty. This will be a two-part process: one part for the program code and one for the Smarty presentation layer. Example 12-3 is the revised program. Once you have typed it in, save it into the temp directory that you created earlier using the filename smartytest.php.

Example 12-3. The sqltest.php program rewritten for Smarty as smartytest.php
<?php // smartytest.php $path = $_SERVER['DOCUMENT_ROOT']; require "$path/Smarty/Smarty.class.php"; $smarty = new Smarty(); $smarty->template_dir = "$path/temp/smarty/templates"; $smarty->compile_dir = "$path/temp/smarty/templates_c"; $smarty->cache_dir = "$path/temp/smarty/cache"; $smarty->config_dir = "$path/temp/smarty/configs"; require_once("$path/temp/login.php"); $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); if (isset($_POST['author']) && isset($_POST['title']) && isset($_POST['category']) && isset($_POST['year']) && isset($_POST['isbn'])) { $author = get_post('author'); $title = get_post('title'); $category = get_post('category'); $year = get_post('year'); $isbn = get_post('isbn'); if (isset($_POST['delete']) && $isbn != "") { $query = "DELETE FROM classics WHERE isbn='$isbn'"; if (!mysql_query($query)) { echo "DELETE failed: $query<br>" . mysql_error() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Database Applications with PHP and MySQL, 2nd Edition

Web Database Applications with PHP and MySQL, 2nd Edition

Hugh E. Williams, David Lane
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 9780596803605Supplemental ContentErrata Page