Foundation PHP for Dreamweaver 8: What you'll learn from each chapter
This brief introductory chapter explains the difference between a static web page (one where the web designer builds the entire page before uploading it to a website) and one that's dynamically generated using PHP, often in combination with a database. After explaining what a server-side language is, the chapter looks at how PHP, the MySQL database and Dreamweaver fit together, and then rounds off with a quick rundown of the PHP features in Dreamweaver 8.
Browsers tend to be very forgiving of mistakes in HTML and XHTML markup, but sloppy code can turn into a disaster when combined with a server-side langage like PHP (ASP, ASP.NET and ColdFusion are just as unforgiving). This chapter looks at all the features in Dreamweaver 8 that will help you avoid such mistakes, along with advice on choosing the right DOCTYPE for your web pages.
Dreamweaver 8 offers the choice of using a testing environment either on your local computer or on a remote website. Instructions are given for both options, but particular emphasis is laid on setting up a local testing server, as this is generally regarded as much more efficient. Detailed, step-by-step instructions lead you through the installation and configuration of the Apache web server and PHP on both Windows and Mac OS X. Windows users are also shown how to configure PHP to work with IIS.
Advice is given on where to locate all PHP files, and on defining your sites within Dreamweaver so that it knows where to find them and can communicate successfully with MySQL. The chapter also contains step-by-step instructions for setting up virtual hosts in Apache on both Windows and Mac OS X.
The book revolves around a case study called East-West Seasons, which contains a random quotation generator, a live news feed, a simple blog, a photo gallery, and an online contact form. This chapter sets up the basic pages for each section of the site, which is built using a standards-compliant, table-free CSS structure.
Since the book assumes no prior knowledge of PHP, this chapter and the following one give you hands-on experience of the language and its structure. There are no silly "Hello, world" examples. You jump straight into doing practical things like including external files and creating a footer that automatically displays the correct year in the copyright statement. By the end of the chapter, you will have learned how to work with text, do arithmetic calculations, and create conditional statements.
This chapter tackles arrays, loops and functions by putting them to practical use in an online form that sends user feedback directly to your email inbox. Particular emphasis is laid on protecting your form from email header injection—a common exploit which attempts to turn your website into a spam relay. The chapter also features a style-switcher that automatically changes your CSS stylesheets at different times of the year.
Now that you have all the basic knowledge to work with PHP, it's time to install the MySQL database management system. Full instructions are given for both Windows and Mac OS X. You also install phpMyAdmin, a free, open-source interface to MySQL, which most hosting companies offer as the main way of administering your online databases.
This chapter shows you how quickly you can integrate a simple online database into your web pages using Dreamweaver's automatic code generation. Using a text file from the book's download files, you create a database containing 50 quotations in seconds, and then use it to display one of them at random. You are shown how to add new quotations, and edit or delete existing ones, building an online content management system with Dreamweaver 8's form creation wizards. You also learn how to insert the code to navigate through a long list of search results one page at a time—a complex task that Dreamweaver solves with just a few mouse clicks.
A key learning feature of the chapter is choosing the correct data type for each column in your database.
Although the single-table database in Chapter 8 is adequate for small projects, you don't get the real benefit of a relational database like MySQL unless you store related information in separate tables. After explaining how to keep track of data through the use of foreign keys, this chapter shows you how to convert the single-table quotations database into two related tables.
You also learn how to use the four key commands—SELECT, INSERT, UPDATE, and DELETE—to interact with a database. The chapter finishes by showing you how to apply Dreamweaver's server behaviors to your own forms to design your own customized content management system.
In this chapter, you see two different ways of creating a user authentication system—first using Dreamweaver 8's built-in server behaviors, and then using a trial version of InterAKT's commercial extension for Dreamweaver, MX Kollection 3. The chapter stresses the importance of verifying user input, and shows you strategies for avoiding filling your databases with duplicate or tainted data.
One of the key learning features is building new server behaviors of your own to extend the functionality of Dreamweaver and speed up your own dynamic website development.
The blog in this chapter isn't intended to be a full-fledged blog, but is used to demonstrate some important and useful techniques, such as populating a drop-down menu automatically with the contents of an images folder (filtering out any files that aren't images), and displaying just the first few sentences of a longer piece of text. The same techniques could be applied equally to a product catalogue, or a staff list. One particularly handy technique ensures that the user is returned to the same point in a multi-page set of search results after viewing a details page.
The photo gallery uses DOM scripting to ensure that large images are displayed without the need either to preload them or to refresh the entire page. Among the useful PHP techniques taught is a custom-built server behavior that automatically calculates the height and width of images before inserting them in a web page.
This chapter shows you how to get the best out of the XSL Transformations server behavior, which is new to Dreamweaver 8. First, you use it to incorporate a live news feed from an RSS source. Then you delve into the mysteries of the XPath Expression Builder to learn how to sort and filter data drawn from an XML file. Although working with XSLT is quite an advanced subject, it's made much easier and more intuitive through the Dreamweaver 8 interface.
This is a brief guide to collation, a feature introduced in MySQL 4.1, which makes it possible to sort database records according to the rules of different languages. Understanding how it works is essential for creating multilingual databases or working with languages other than English.
A quick guide to backing up data and transferring it to another server, upgrading MySQL, and what to do when you forget your MySQL root password.