Table Of ContentPHP Web Development
with Macromedia
Dreamweaver MX
2004
ALLAN KENT AND DAVID POWERS WITH RACHEL ANDREW
ApreSSQ/
PHP Web Development with Macromedia Dreamweaver MX 2004
Copyright © 2004 by Allan Kent, David Powers, Rachel Andrew
Originally published by Apress in 2004.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
me ans, electronic or mechanical, inc1uding photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and
the publisher.
ISBN 978-1-59059-350-9 ISBN 978-1-4302-0701-6 (eBook)
DOI 10.1007/978-1-4302-0701-6
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Chris Mills
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
John Franklin, Jason Gilmore, Chris Mills, Steve Rycroft, Dominic Shakeshaft, !im Sumser,
Karen Watterson, Gavin Wray, John Zukowski
Project Managers: Nate McFadden, Laura Cheu
Copy Edit Manager: Nicole LeClerc
Copy Editor: Marilyn Smith
Production Manager: Kari Brooks
Production Editor: Janet Vail
Compositor: Susan Glinert Stevens
Proofreader: Liz Welch
Indexer: Valerie Perry
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 233 Spring
Street, 6th Floor, New York, NY 10013 and outside the United States by Springer-Verlag GmbH &
Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany.
In the United States: phone 1-BOO-SPRINGER, e-mail [email protected]. or visit
http:/ /www.springer-ny.com. Outside the United States: fax +49 6221345229, e-mail
[email protected], or visit http://www.springer.de.
For information on translations, pIe ase contactApress directly at 2560 Ninth Street, Suite 219,
Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit
http://www.apress.com.
The information in this book is distributed on an "as is" basis, without warranty. Although every
precaution has been taken in the preparation ofthis work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.comin the
Source Code section.
Contents at a Glance
About the Authors ............................................................................................... ix
Introduction ......................................................................................................... xi
Chapter 1 Introduction to PHP ............................................................. 1
Chapter 2 Introduction to MySQL and SQL ..................................... 27
Chapter 3 Introduction to Dreamweaver MX 2004 ........................ 61
Chapter 4 Web Standards in Dreamweaver ....................................... 83
Chapter 5 Data Manipulation and Server Behaviors ................ 153
Chapter 6 Code Reuse with Dreamweaver and PHP ...................... 203
Chapter 7 Dreamweaver Extensions ................................................... 247
Chapter 8 Debugging and Error Handling ..................................... 295
Chapter 9 Case Study: Roundtree Garden Club ........................... 341
Appendix Setting Up Your Environment ........................................ 461
Index ...................................................................................................................... 505
iii
Contents
About the Authors ....................................................................................... ix
Introduction .................................................................................................... xi
Chapter 1 Introduction to PHP ..................................................... 1
What Exactly 1s PHP? ......................................................................................... 1
The PHP Language .................................................................................................. 3
Summary ................................................................................................................... 26
Chapter 2 Introduction to MySQL and SQL ......................... 27
Administering Your Database ........................................................................ 27
Creating a Database ......................................................................................... 40
CreaUng a User with Rights ........................................................................ 42
Creating a 5ample Table ................................................................................ 46
Manipulating Data .............................................................................................. 53
Summary ................................................................................................................... 59
Chapter 3 Introduction to Dreamweaver MX 2004 .......... 61
Changes in Dreamweaver MX 2004 ................................................................. 61
Setting Up a 5ite .............................................................................................. 71
Managing Your 5ite ........................................................................................... 77
Summary ................................................................................................................... 81
Chapter 4 Web Standards in Dreamweaver ............................ 83
Authoring Valid XHTML ..................................................................................... 83
Authoring Valid C55 ......................................................................................... 96
Using C55 Tools in Dreamweaver MX 2004 .............................................. 101
Creating Valid Markup ................................................................................... 113
Using C55 for Layout ..................................................................................... 134
Addressing Browser and Device 1ssues .................................................. 145
Working with Dynamic Data .......................................................................... 150
Summary ................................................................................................................. 151
v
Contents
Chapter 5 Data Manipulation
and Server Behaviors ............................................... 153
Setting Up a Database ................................................................................... 153
Connecting Web Pages to a Database ....................................................... 157
Using Recordsets to Retrieve Data ......................................................... 159
Adding New Records to a Database ........................................................... 166
Displaying Data from a Database ............................................................. 169
Modi fying Data in a Database .................................................................... 176
Reporting Database Information ............................................................... 196
Summary .................................................................................................................. 201
Chapter 6 Code Reuse with Dreamweaver and PHP ........ 203
Using Dreamweaver Templates ...................................................................... 203
Recycling Code with Dreamweaver Library Items ............................... 221
Building Your Own Code Library ............................................................... 226
Including Code from External Files in PHP Pages .......................... 236
Summary .................................................................................................................. 244
Chapter 7 Dreamweaver Extensions .......................................... 247
Introducing the Extension Manager ......................................................... 247
Getting and Installing Extensions ......................................................... 249
Creating Your Own Extensions .................................................................... 256
Packaging Extensions ..................................................................................... 289
Summary .................................................................................................................. 294
Chapter 8 Debugging and Error Handling .......................... 295
Syntax Errors ..................................................................................................... 296
Dreamweaver MX 2004 Features to Help Avoid Syntax Errors ....... 304
Runtime Errors .................................................................................................. 311
Logic Errors ....................................................................................................... 326
Debugging Techniques ..................................................................................... 333
Summary .................................................................................................................. 340
vi
Contents
Chapter 9 Case Study: Roundtree Garden Club ............. 341
An Overview of the Project ........................................................................ 341
Planning and Creating the Database Tables ....................................... 343
Building the Administration Section .................................................... 353
CreaUng the Public Face of the Web Site ......................................... 417
The Road Ahead .................................................................................................. 458
Appendix Setting Up Your Environment .............................
461
Setting Up in a Windows System ............................................................... 461
Setting Up in a Mac OS X System ............................................................. 487
Setting Up Dreamweaver MX 2004 ............................................................... 500
Index ...................................................................................................................
505
vii
About the Authors
Allan Kent has been programming seriously for the past 10 years or so, and other
than a single blemish when he aehieved a diploma in Cobol programming, is
entirely self-taught. He started his eareer working at the loeal university and now
eo-owns a eompany that does new media design. Allan lives in Cape Town, South
Afriea, with his girlfriend and four eats.
David Powers has been professionally involved with the eleetronie media for 30 years,
mostly in radio and television. He was a BBC Tokyo eorrespondent in the late 1980s
and early 1990s, but more reeently has eoneentrated on Internet projeets. He built
his first web site in 1995, and was instantly hooked. Eventually, the sheer tedium of
updating eontent eonvineed hirn there must be a better way. After abrief flirtation
with ASp, he experimented with PHp, and found hirns elf hooked yet again. Fluent
in Japanese, David speeializes in building Japanese-English bilingual web sites,
writing about Japan, and translating Japanese (he has translated several plays). He is
eoauthor of Foundation Dreamweaver MX 2004 (friends of ED, 2004), and has worked
as teehnieal reviewer on a number of web-related titles for the Apress group.
ix
Introduction
HELLO, AND WELCOME to PHP Web Development with Macromedia Dreamweaver
MX 2004. This book aims to provide you with an essential, one-stop guide to
mastering PHP web si te development on the PC or Mac, using Dreamweaver MX
2004 as your tool of choice. If you are a novice at using Dreamweaver or building
PHP web sites, or ifyou do have prior experience and want to familiarize yourself
with the new features provided in Dreamweaver MX 2004, this book is for you.
The technologies you will be working with in this book are as follows:
Dreamweaver MX 2004: The newest version of Macromedia's best- selling
web design and development tool, which boasts more than three million
users worldwide. The newversion comes with major improvements, such
as a more streamlined intuitive interface, improved integration with other
programs, improved support for web standards, and much more.
PHP: The most popular server-side scripting language in existence, PHP
allows you to create powerful, dynamic web sites. Web site development
with PHP is made even easier through its support in Dreamweaver (since
UltraDev 4) as a server model. The version of PHP covered in this book is
4.3.4, although some allusions are made in appropriate pI aces to usage of
the forthcoming new version, PHP 5 (currently in final beta stages).
MySQL: By far, the most widely used, open-source relational database
management system, MySQL has long been the database solution of
choice to use with dynamic PHP web sites, and it's the one supported in
Dreamweaver. The version we cover in this book is the latest stable
version, 4.0.
Apache: The open-source web server of choice to serve PHP/MySQL web
sites, and the one expected by Dreamweaver (are you are seeing a pattern
here?). Versions 1.3 and 2.0 are both popular. In this book, we cover
Apache 2.0 on Windows, because it is designed with Windows in mind,
and Apache 1.3 for Mac, as it comes already installed (on OS X).
Chapters 1 through 3 of this book introduce the features of PHp, MySQL, and
Dreamweaver MX 2004, respectively. The book's appendix provides an extensive
step-by-step guide to setting up your Apache/PHP/MySQLlDreamweaver MX
2004 environment, for PC and Mac systems. After you have your installation sorted
out and mastered the basics of the technologies you will be using, we delve deep
into Dreamweaver's features.
xi
Introduction
• We look at web standards in Chapter 4, including working with XHTML and
Cascading Style Sheets (CSS) in Dreamweaver, validating your XHTML
pages against the different XHTML Document Type Declarations (DTDs),
and allowing older browsers to view your pages.
• Chapter 5 is dedicated to data manipulation and server behaviors. Here, we
go into depth on how to design and build a MySQL database, and how to
connect it to a PHP web site via Dreamweaver. We cover using recordsets to
retrieve data, modifying and deleting that data, and using it on your PHP
pages through Dreamweaver server behaviors.
• Code reuse is the focus of Chapter 6, where we look at methods available in
Dreamweaver and PHP to reuse sections of code in your web pages, saving
you a lot of time and effort in the process. Specifically, we look at Dream
weaver templates, library items, snippets, and PHP includes.
• Dreamweaver extensions are covered in Chapter 7. We describe what exten
sions are and how they are used. Then we explain how to build your own
extensions and package them so they can be made available to others.
• We go into debugging and error handling in Chapter 8, looking at how to
spot, correct, and prevent syntax, runtime, and logic errors.
We round off the book with a comprehensive case study in Chapter 9, which
shows how to plan, design, and implement a complete PHP IMySQL web site using
Dreamweaver. This case study uses many of the techniques covered in the book
and includes a wealth of typical features that you might implement on a dynamic
web site. These include an online contact form, a member login page, a blogging
system (where registered members can add articles to the site) , and much more.
Remember that you can download the source code for the book from
http://www.apress.(am.This will save you the trouble of typing everything in! We
are confident that this book will be a great learning tool to you, and we hope that
you have as much fun reading it as we did writing it.
Enjoy!
xii