APPENDIX Setting Up Your Environment

PHP IS A SERVER-SIDE scripting language and, as such, needs a web server in order to function in the way that this book describes. Your web server needs to under­ stand what a PHP document is and have the software installed to handle the PHP document correctly. The web server we use in this book is Apache. The scripts in this book are connecting to a MySQL database server, and you will also need to have this server installed. In this appendix, we provide you with a one-stop shop for downloading, installing, and setting up the software you need to get your computer up and running as a PHP-enabled web server with a MySQL database. We will first look at how to go about setting up your system in a Windows environment, and then see howyou can da the same under Mac OS X. Finally, we will take a look at how to instali Dreamweaver MX 2004.

Setting Up in a Windows System

Ta get your Windows system up and running, you need to install Apache. You also need to install and configure PHP and MySQL.

Installing and Configuring Apache

There are a number of different options available when choosing a web server, but perhaps the most popular web server on the Internet at the moment is Apache. This web server was originally written to run in a Unix environment. However, the growth ofWindows-based servers over the years has prompted the Apache Group to bring their Windows version of the Apache web server to the same level of stability, performance, and security as its Unix counterpart.

Downloading Apache

Your first step is to download the Apache web server package. Browse to the http://www . apache. arg web si te and follow the links to the httpdproject. When you

461 Appendix

are there, dick the Download link (http://httpd.apache.arg/dawnlaad . cgi) and download the latest Win32 version. The version that we downloaded to install is Apache 2.0047. The file for this version is apache_2.004 7 -win32-x86-no_ssl.msi, which is a Windows installer that will step you through the entire installation process. This version doesn't have Secure Sockets Layer (SSL) support built in, which is fine, because we don't need SSL for this book, and without it, the download is smaller. The installer without SSL weighs in at ab out 6MB.

Installing Apache

Once you've downloaded the Apache installation file, follow these steps to install the web server:

1. Double-dick the file in Windows Explorer to start the installation process. Figure 1 shows the Welcome to the Installation Wizard screen.

wek:ome to the Instalation WlZard for Apache lfTJP Server 2.0.47

The Installation Wizard will instaU Apadle HfTP Server 2.0.47 on yoo.x CDOlputer. To oontinue, dick Ne.xt

WARNING: This program is protected by copyrightlaw and in tema oonal trea ties.

Next>

Figure 1. Beginning to install the Apache web server

462 Setting Up Your Environment

2. Click Next, select the radio button to accept the terms of the License Agreement, and dick Next again.

3. The next screen displays information about the Apache HTTP Server. Click Next, and you will be prompted to enter yom basic server infor­ mation, as shown in Figme 2.

IWI Apache HTTP Server 2..0 - Installation Wizard 1 Server Information Please enter your server's nfurmation.

NetworltQomain (e.g. somenet.com)

~er Name (e.g. www.somenet.com):

A'*ninistrator's gnaiI Address {e.g. [email protected]):

(nstal Apache HTTPServer 2.0 programs and shortoJts fur:

(.' for AB Users, on Port 50, as a Service - Rec.ommended. r onIy fur the G..I'rent User, on Port 8080, when starte

Figure 2. The web server installation needs so me information from you.

4. Enter fom pieces of information:

Network Domain: This is the network domain in which yom server is installed. Ifyou are setting up a server that is visible on the Internet, yom server probably is part of a domain. The publishers of this book would install their servers in a network domain of apre55. com. If you are running yom server at horne, you can use localhost. Server Name: This is the fully qualified domain name of this machine, and it identifies the individual machine. The server name will always be an address within the domain that you specified in the previous entry. If om network domain is apre55. com, for example, om server

463 Appendix

name might be dreamweavermxbook. apre55. com. Horne users who will never be using their machine as a web server live on the Internet can use localhost as the server name as well as the network domain. Administrator's Email Address: This is the email address that will appear in any of the server's default error messages that are displayed to users. How to Install Apache: Your options are to install Apache as a service that will be started automaticallywhen Windows starts, even before anyone has logged on to the machine, using port 80 to listen for requests. This is the default port for web traffic, and you should use this option, unless you already have another web server running on port 80. In that case, choose the option for the Current User on port 8080. Ityou choose the second option, you will need to manually start Apache each time before you can use it, and you will also need to browse using port 8080 when testing your pages, as described in the next seetion.

NOTE Each application server that runs on your machine needs to "listen" for incoming connection , and it need to do 0 on it own port number. Port 80 is the default port for a web server to li ten on, and ifyou us it, you wiIJ not need to tell your web brow er to brow e on a special port for the Apache web server. Ifyou need to run two different web erver on your machine-Apache and Microsoft Internet Information erver (11 l. for example-they would need to listen on different port , ince only one prograrn can listen on a specific port at any given time. You would need to change either II or Apache to li ten on a port other than 80.

5. After you have entered the required information, dick Next to move to the Setup Type screen. Your choices are Typicalor Custom. A Typical instal­ lation will have everything that you need to get up and running. The Custom installation allows you to deselect the documentation and he ader files, if you want to compile and link additional Apache modules.

6. Click Next again, and you will be able to change the destination folder where Apache installs. This defaults to C: \ Program Files \Apache Group \, and the rest of this appendix assurnes that you have left this default setting.

464 Setting Up Your Environment

7. Click Next, and then dick the Install button. The installation will begin and you will see a progress bar showing the status of the procedure, as shown in Figure 3.

I ~ Apoehe HTIP Server 1.0 - Installation Wtzard !J

Installing Apadre HTIP Server 1.0.47

The program features you selected are ~instaDed.

PIease wait whde the Instalation Wizard instals Apache HTTP Server 2.0.47. This may take several minutes.

Status: Copyng new files I ......

:rtanShI~d------, __e:_B_ ack__ ,--_ 'J_eJ_t_;._~II... __cancel __ ......

Figure 3. Apache installation progress

8. During the installation process, a number of Command Prompt windows will pop open on your screen, and then automatically dose. This is the Apache installation program registering and starting the web service. Once the installation process has finished running, you will be informed that the installation is complete, as shown in Figure 4. Click Finish to exit the Installation Wizard. You should not need to reboot your machine after the installation.

465 Appendix

Instalation Wuard Completed

The Ins taHa lion Wizard ha s successfuly instaIled Apache HT1P Server 2.0.47. Ode Finish to exil the wizard.

CanceJ

Figure 4. CompletedApache installation

Starting and Testing the Web Server

When the installation is completed, you will have a new item in yom Start menu for Apache HTTP Server. Hyou chose the default installation of Apache running as a service, the installer will have already started the Apache service for you, and you can test the installation by opening yom web browser and entering the URL http://localhost, as shown in Figme 5.

466 Setting Up Your Environment

Jfyou can see tbis, it means that the installation ofthe Apache web server software on tbis system was successful. Yon may DOW add cooleul to tbis directory and replace tbis page.

Seeing thi instead of the website you expected?

'Ibis page is here because the site administrmor bas changed th.e configmation oftbis web server. Please CODfaCt file persoD respoDsible for mamtalruDi tllis server witla qD estioDs. Tbe Apache Software Foundation. which wrote the web server software Ibis sile admiDistratar is using, has nothing to da with maintaining this site and cann.ot help resol\"e configuration issues.

Tbe Apache docnmentation has been included with this distnbution.

You are free to use tbe image beJow on an Apache-powered web server. Thanks far using Apache!

_ ".,...... P.A.C t-I E

Figure 5. Browsing yaur newly installed site

Hyou installed Apache to be started manually, you will need to navigate to the Apache HTTP Server submenu in the Start menu and start the Apache server yourself. Once it has started, you can then test the installation by opening a web browser and browsing to the URL http://localhost : 8080.

lf you can see this. it means tbat tbe installation of tbe Apache web server sofl

467 Appendix

This is the default page that comes with Apache. In the "Configuring Apache to Use PHP" section later in this appendix, you williearn how to remove this page and make your own pages appear here instead.

Configuring Apache

We will not go into great detail about how to alter and configure your server; the manual that comes with Apache has a section that explains each and every possible configuration option (http://localhostlmanual/ configuring. html). Here, we will look at some of the common configuration options that you might want to change. Ey default, Apache will have installed in the C:\Program Files\Apache Group\ Apache 2 \ directory, and you will find all of the files that Apache needs to run in this directory, as shown in Figure 6.

AeFdder Fddet AeFdder"* AeFdder "* Fdder bi\ "* Fdder 0jI-M "* Fdder anf "* Fdder error "* Fdder hldocs Fdder F*Fdder"* KIlnS poxy nO..de "* Fdder AIIOJT_N'AOEtxt 15 i'lJ Text lloar.Iul Ib lBl QfANG6. txt 583 i'lJ Text Doo..rnent /og$ rn tj lNST1<1. txt ~i'lJ TextOoanent mn01 Gl u~.ll

Figure 6. The Apache 2 directory structure

The main configuration for Apache 2 resides in the conf directory and is called httpd.conf. Open this file in Notepad, Homesite, or Dreamweaver's Codeview.

468 Setting Up Your Environment

The httpd.conffile is divided into three main sections:

• The first seetion contains global configuration directives, which determine how the Apache server performs as a whole. This section contains infor­ mation such as where the files are installed, which port to listen on, and which modules are instalied and loaded.

• The second seetion contains the configuration for the main or default web server. The Apache web server allows you to easily set up virtual hosts. This means that you can run more than one web server on the same machine, each with its own set of document files, log files, and even domain name.

• The third section of the configuration file is where you can set up virtual hosts.

You will probably have noticed that there are a number oflines within the con­ figuration file that begin with a hash character (#). These are comment lines. Any lines in the httpd.conffilethatbeginwitha#characterareignored by Apache. You can use the # character to add your own comments, or to simply comment out the default configuration setting before adding your own.

Setting Up the Global Environment

The first configuration that you can change in the global environment is where the Apache web server is instalied. This is set by the installer during installation and uses the value that you selected as the location for the web server to be installed.

Web Server Installation (ServerRoot)

The web server installation defaults to the following location:

ServerRoot "C:/Program Files/Apache Group/Apache2"

NOTE otice that even though you are working on a Window -ba ed machine, you still use forward slashe as the delimiter between directory name. Window normally uses a backslash character (\) between directory names, but Apache was originally written to run in a Unix environment, which u es forward sla hes between dir ctory name, and thi ha been retained as a tandard.

469 Appendix

Web Server Timeout

You can also control how long the Apache server waits before timing out when sen ding or receiving a page. The following directive specifies the time in seconds for the server timeout:

Timeout 300

Web Server Port (Listen)

When you instalIed Apache, you were given the option of installing Apache as a service listening on port 80 or as a program to be started manually and listening on port 8080. Ifyour machine alreadyhas a web server (such as IIS), port 80 will already be in use. You cannot have two services using the same port. If you want to change the port that Apache uses, you can do that in this section of the configuration file, by changing the following line to specify the port number that you want the web server to listen on:

Listen 80

The Listen directive is also useful ifyour machine is connected to the Internet bya cable modem, and you don't want anyone on the Internet to be able to browse your machine's web server. Ey default, Apache will listen on every available IP address that is assigned to your machine, including both the localhost IP number (127.0.0.1) and the IP number that was assigned to you byyour ISP. As part ofthe Listen directive, you can explicitly specify the IP address that Apache must listen on:

Listen 127.0.0.1:80

Ifyou specify this as your Listen directive, you will be able to browse your machine onlyfrom the machine on which theweb server is installed. Ifyour machine is also part of a small horne network, you specify the IP address ofyour machine within that network:

Listen 10.0.0.10:80

This way, the other servers on your network can browse the web server, but computers on the Internet cannot. In the section on configuring Apache with PHP a bit later, we will take a look at how to instalI and load additional modules into Apache.

470 Setting Up Your Environment

Setting Up the Default Environment

The default environment is simply the settings that are used if no virtual hosts are defined. All ofthe configuration directives that you can use within the default section can also be used within a virtual host definition.

Hast Dacument Files (DacumentRaat)

One directive that you are likely to want to change is the directive that specifies where the document files for this host are located. By default, the document files are stored in the htdocs directory off the main server root directory:

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"

Personally, we don't enjoy digging around in the Pro gram Files directory to find the files for our web sites, so this is normally the first directive that we change. If you have a single directory where you keep all of your work, you can use this as the document root. For example, if you have a directory called htdocs in the root directory of your C: drive, where you keep all the web files for sites you're working on, you could use the following setting:

DocumentRoot "C:/htdocs"

Once you have changed the DocumentRoot setting, you will also need to find the directive that controls that directory. The directive lets you set features and options for each individual directory that Apache can access. Look for the following line:

Change it to the directory you chose for your DocumentRoot, as in this example:

Directary Index

As you continue looking down the httpd.conffile, notice the following line:

DirectoryIndex index.html index.html.var

471 Appendix

This line defines the names of files that Apache will serve as a directory index. This means that if someone does not specify the name of the file on the end of the URL, Apache will look for a file in that directory that corresponds to one ofthe filenames given in the Directorylndex directive and display that file. Ifyou are used to the Microsoft system of naming files, you will want to add index.htm as a filename to the Directorylndex directive. This is a space-delimited list; don't use commas or semicolons to separate the elements in the directive:

Directorylndex index.html index.html.var index.htm

Aliases

If you have a directory of web documents that you want to make available on YOUf web server, but they do not reside within the directory structUfe that you specified in the DocumentRoot directive, you can create an alias to the directory, and Apache will serve it out as ifit were a subdirectory OfyOUf DocumentRoot. Aliases are created with two directives. The first is the Alias directive itself:

Alias /icons/ "C:/Program Files/Apache Group/Apache2/icons/"

Here, an alias of /icons/ is added. When a user browses to the /icons/ directory on YOUf web server, Apache knows that the files are actually located in the C:\Program Files\Apache Group\Apache2\icons directory. If you create an alias, you also need to create a directive that specifies how to handle that specific directory:

Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all

The directory specified is the same directory referred to by the Alias directive. In the directive, you can specify how this directory is displayed by the web server, as well as control who can browse the content.

Creating Virtual Hosts

The easiest way to describe a virtual host is that it is like an alias, but it is identified by its own unique host name rather than just a directory. A great use of virtual hosts is if YOUf web server is running on a machine that straddles two networks­ YOUf Internet connection on one network adapter and YOUf local network on the

472 Setting Up Your Environment other. Ey setting up virtual hosts, you can serve one set of web pages to the machines on your local network and a different set of pages to clients on the Internet. If you are not running a server in this configuration, but want to use virtual hosts anyway, you will need to first add the host names that you want to use to your hosts file. To do this, open a Command Prompt window and change to System32\ drivers\etc within your Windows directory so that you can edit the hosts file, or if you prefer, open the file C:\ Windows\ System32 \ drivers \ etc\HOSTS in Notepad. Then look for a line at the beginning of the file that reads like this:

127.0.0.1 localhost

Add a new line to the file that includes the host name. For example, to add the host apress, add this line:

127.0.0.1 apress

Once you save this file, you will be able to use the host name, apress in this example, as an additional host name for your local machine. Next, you need to tell Apache to handle requests with the host name differ­ ently. At the bottom of the httpd.conffile, look for a line that reads like this:

#NameVirtualHost *

And remove the # comment character from the beginning of the line. This tells Apache that you want to use named hosts. Now, you need to tell Apache what these virtual hosts actually are. Add the following lines for the local host and the new host name (apress, in this example):

DocumentRoot "c:/Program Files/Apache Group/Apache2/htdocs Server Name localhost DocumentRoot c:/work/apress/htdocs ServerName apress

You need to provide only two directives for the virtual host to work. The first, DocumentRoot, specifies where the document files for this host will reside, and the second, ServerName, specifies the host name that this virtual host will respond to. Note that we are also adding the localhost server name here. When you use virtual hosts, you will need to explicitly name the local machine and any hosts you create. In this example, we can still browse the default Apache web site installation through

473 Appendix

the localhost server name, and also browse our own Apress-related files through the apress server name. Hyour machine were on the Internet, you would use the fuHy qualified domain name. Save the httpd.conffile, and then restart the Apache web server by selecting Start ~ Programs ~ Apache HTTP Server 2.0.47 ~ ControlApache Server ~ Restart.

CAUTION The directory that you pecified for your Document Root in the default ection of the configuration, a weil as the DocumentRoot directories that you specified for any virtual ho t , mu texist; otherwise, Apache will not start.

Once you've restarted Apache, you can test your new settings and virtual host. You might see a page like the one shown in Figure 7.

'l403 Forbidden . f' hcro~ft ":

Forbidden

You don't have pennission to access I ou Ibis stfVer.

Apach .0.47 (JVm32) Servi!f ot apress Pon 80

Figure 7. A less than positive outcome

This rather severe-looking page wiH appear when Apache cannot find a file to use for the DirectoryIndex for the virtual host. Remember the DirectoryIndex directive that you set up in the httpd.conffile? WeH, this is the file that Apache will display when you browse to a si te and don't include the filename on the end of the address. In this example, the directory that we set up to store our virtual host files is currently empty, so Apache simply shows us a rude message. To resolve this

474 Setting Up Your Environment problem, create a simple index. file and save it in the directoryyou specified as YOUf DocumentRoot for the virtual host.

Installing and Configuring PHP

PHP is the driving force behind the dynamic pages that we create throughout this book. Since PHP is a server-side language, you will need to install it at a server level so that the web server can handle the PHP pages before they are sent to the browser. In this appendix, we will show you how to install PHP within the Apache web server. Hyou are using a different web server, see the PHP Manual at http://www . php. net for details on installing PHP (it has instructions for all the popular web servers).

Downloading PHP

PHP is freelyavailable from the http://www. php. net web site, as well as from alarge number of mirror sites around the world. The PHP download page will try to determine the dosest mirror to you or allow you to select the mirror of YOUf choice. At the time of writing this book, the latest version of PHP available was PHP 4.3.4. (See the section titled "Downloading and Installing PHP 5" later in this appendix, if that version is available when you are ready to download PHP.) The installation comes in two flavors: a Windows installer that contains just the basics you need to get PHP up and running or a Zip archive that contains PHP and all ofthe installable extensions. The installer version will install only the Common Gateway Interface (CGI) version of PHp, and it cannot automatically configure Apache for you. FUfthermore, the self-installing version does not contain PHP extensions, which offer extra functionality. The file that you will want to download from the http://www . php. net web site is php-4.3.4-Win32.zip, and it is a little over 6MB in size.

Installing PHP

You can run PHP either as a CGI program or as a Server Application Interface (SAPI) module within YOUf web server. The php-4.3.4-Win32.zip download indudes the files for both. These two different versions are stored in different places within the PHP installation. The CGI version of the PHP executable is php.exe and resides in the C:\php-4.3.4-Win32 directory. The executable file for the module

475 Appendix

version of PHP differs depending on YOUf web server, but all of the executable files are in the C:\php-4.3.4-Win32\sapi directory. We recommend using the SAPI module version of PHP. CGI is the original method that web servers used to call external programs. The web server would take the request, pass control of that request to the external CGI program, and then simply send the output of that program back to the web browser. The SAPI module offers a direct interface between the web server and the application that it needs to run (in this case, PHP). Because the SAPI modules run within the web server environment, they are both faster and more seCUfe than the CGI versions. After you have downloaded the php-4.3.4-Win32.zip file, extract it to YOUf C: drive. It will extract to a folder named C: \ php-4.3.4-Win32. Next, you need to copy the files required by PHP. You could copy the files into YOUf Windows directory, but that would be rather messy and might cause DLL conflicts. Instead, we suggest that you copy all of the DLL files that PHP needs to run into a new directory under the PHP installation. This way, all the DLL files are in the same place. If you upgrade to a new version of PHp, you won't need to hunt through YOUf search path and Windows directories to find DLLs that need to be replaced, and you won't have problems with incorrect versions of DLL files.

CAUTION The instant messenger program GAJM u es iconv.dll, and this OLL file is also included with the PHP installation. Ifyou simplycopythe OLLs that come with PHP into YOllr Windows Sy tem32 directory, the next time YOll tart GAIM, it will find PHP' ver ion oficonv.dll. Ifthi i not the same ver ion a the OLL that shipped with GAJM , your instant me senger program will fail to load.

Create a new directory under the PHP installation called apache2- C:\php-4.3.4-Win32\apache2. Copy two files into this new apache2 directory:

• The php4ts.dll file, which PHP always needs. (This is the DLL file for PHp, and it needs to be copied either to a place in YOUf PATH or to the same directoryas the executable file that you will be using for PHP.)

• The correct SAPI module. For Apache 2, this is the php4apache2.dll file that you will find in the sapi directory. (The files in the dlls directory are the DLL files that you might need for certain PHP extension modules that you can install.)

The last file that you need to copy is the configUfation file for PHp, which is the only file from the PHP distribution that needs to be copied to the Windows directory.

476 Setting Up Your Environment

• In the root of the directory where you extracted the PHP Zip archive, you will find a file called php.ini -recommended. Copy this file to the C: \ Windows directory and rename it to php.ini.

Configuring PHP

Before you can configUfe Apache to use PHp, you need to configUfe PHP itself. Using Notepad or a similar text editor program, open the C:\ Windows\php.ini file.

Tag Style

One of the first items that you can change in the PHP configUfation is how you escape between HTML and PHP code in YOUf PHP pages. The full and proper way of opening a block of PHP code is with . Ityou want, you can use the following directive:

This way, you can start a PHP code block with

Ifthis page also needs to contain some PHP code, the PHP engine will interpret the openingXML tag as the start ofPHP code and tryto execute the code immediately after it. For this reason, we always set the short_ open _tag directive to Off:

Another directive that handles how PHP is delimited is related to the use of ASP-style tags. By default, this directive is set to Off:

Ityou want to be able to sUfround YOUf PHP code with the <% and %> tags, just as you can in ASp, you can set it to On: asp_tags = On

However, you should enable this option only if it is really necessary. Writing code that relies on the directive being On will make YOUf code less portable to other serv­ ers and machines.

477 Appendix

Global Variables

In the Data Handling section of the php.ini file, the register_globals directive is disabled by default:

register_globals = Off

In previous versions of PHP (before version 4.2.0), this directive was set to On. This meant that any variables that you set in a form or via the URL query string were in the global scope by default, and YOUf PHP script had immediate access to them as if they were variables that YOUf script itself had set. This made badlywritten scripts susceptible to having variable values injected into them that were not nec­ essarily meant to be used, making YOUf scripts, and therefore YOUf web si te and database, vulnerable to hackers. Therefore, it is strongly recommended that you leave this directive set as the default of Off.

NOTE ome older scripts that you can find on the Internet are written in such a way that they rely on the register_globals directive being et to On. 0, following the recommended practice doe mean you won't be able to use every prewritten cript you find on the Web.

Sessions

Ityou use the Session variable in any OfyOUf scripts, the directives that fall under the [Session] section ofthe configUfation file will come into play. The important one to notice is this directive:

session.save_path = /tmp

This specifies the directory where PHP will store temporary session data. One way to make SUfe that YOUf sessions will work correctly is to create a directorywithin YOUf main system drive (C:/tmp), and then change the value of the session. save _path directive to point to this new directory:

session.save_path = "C:/tmp"

Alternatively, you can change the value in this directive to a temp directory that already exists on YOUf machine.

478 Setting Up Your Environment

Additional Extension Modules

If you intend to load some of the additional extension modules in PHp, you first must make sure that PHP knows where to find them. Ey default, the extension_dir directive is set as follows: extension dir = ".1"

This teIls PHP to look in the same directory where PHP itself is located. Although you could copy the extension DLL files that you want to use within PHP into the apache2 directory that you created earlier, it makes more sense to just point the php.ini file to the directory that holds the DLL files-the extensions directory within your PHP installation. Ifyou used the default directory naming that we suggested when unzipping the PHP archive, change the extension_dir directive to the following: extension dir = "c:/php-4.3.3-Win32/extensions/"

All of the modules that you can load into PHP are already included in the php.ini file, but commented out. To enable an extension, all you need to do is find the line for the extension that you want to use, and then uncomment it by removing the ; character from the beginning of the line. We recommend that you enable the GD image libraries in PHP so that you can dynamically create and manipulate images from within PHP. Find this line:

;extension=php_gd2.dll

And uncomment it so that it reads like this: extension=php_gd2.dll

The GD extension does not need any additional DLL files, but some extensions do require additional DLL files to work correctly. You can find these DLLs in the dlls directory within the PHP installation. If you have added an extension that needs additional DLLs, just copy them from the dlls directory into the directory where you copied php4ts.dll, and your extension will work.

Configuring Apache to Use PHP

Now that you have configured PHp, you can set up Apache to handle PHP scripts. Once again, open the httpd.conffile for Apache in Notepad, Macromedia Homesite, or Dreamweaver's Code view, and make the following changes:

479 Appendix

1. Search for the text LoadModule. You will see a number oflines that are loading various modules into Apache. You will need to add the PHP module to this list. At the bottom ofthe list of LoadModule directives, add the following line to add the PHP module:

LoadModule php4_module c:/php-4.3.4-Win32/apache2/php4apache2.dll

This assumes that you created the apache2 folder, as recommended earlier in the appendix. The path that you give to the php4apache2.dll file needs to correspond to wherever the php4apache2.dll file resides on YOUf system.

2. The next step is to tell Apache that it must handle PHP files using this newly loaded module. YOUf Apache installation httpd.conffile should have some AddType directives in it. Search for them and add the one for PHP onto the end:

AddType application/x-httpd-php .php

This tells Apache that when it encounters a file that has an extension of .php, it must use the PHP module to handle the page contents.

3. Then, just to make things neat and tidy, search for the line that you edited earlier telling Apache which files to use instead of displaying directory indexes in the browser. You already added the index.htm file to the list, so that people used to the Windows naming convention would still have their files displayed correctly. Now, add index.php to the list, so that you can have a PHP page displayed by default:

Directorylndex index.html index.html.var index.php

Downloading and Installing PHP 5

The PHP 5 directory layout differs slightly from that of PHP 4, so if you are going to download and install PHP 5 when it is released, you will need to amend the instal­ lation instructions given he re slightly. Going by the standard naming convention used for PHP distributions, we expect the download to be called php-5.0.0-Win32.zip. Download this file and extract it to a C:\ php-5.0.0RCI-Win32 directory.

php.ini File Changes

The first set of changes you will need to make are to YOUf php.ini file:

480 Setting Up Your Environment

• The extensions directory is now just simply the ext directory. Change the extension dir directive to read as follows:

extension_dir = "C:/php-s.O.O-Win32/ext/"

• MySQL is not enabled by default in PHP 5. In order to use MySQL, you will need to uncomment (remove the ; character from the beginning) the following line:

;extension=php_mysql.dll

• Ifyou are using an existing php.ini file from PHP4, you will not have this line (because MySQL was built in), so you will need to add it to the section ofthe php.ini file that lists all of the extensions. Then copy the libmysql.dll file to your C: \ Windows \ System32 directory so that your system can find the file when PHP needs to use it. httpd.confFileChanges

The only change that you need to make in the Apache httpd.conffile is to the following line:

LoadModule php4_module c:/php-4.3.4-Win32/apache2/php4apache2.dll

For PHP 5, change it to read like this:

LoadModule phps_module c:/php-S.o.o-Win32/phpsapache2.dll

Remember to restart Apache once you have made these configuration changes.

Restarting Apache and Testing Your Installation

All that is left to do is restart the Apache web server and test that the installation has worked. Make sure that you have saved the changes you made to the php.ini and httpd.conffiles, and then restart the web server by choosing Start >- Pro grams >­ Apache HTTP Server 2.0.47 >- ControlApache Server >- Restart. If you have set up everything correctly, you should not have any errors, and the Apache web server will be running. If there was something wrong with any of the changes that you made to either of the configuration files, note the error message that pops up, fix the problem in the configuration file, and restart Apache again. Typical errors are paths that are incorrectly entered in the configuration.

481 Appendix

Once Apache has restarted, create a simple PHP file to make sure that PHP is working. Create the file index.php and enter the following PHP code:

<7php phpinfo() ; 7>

This PHP function simply prints all of the information about PHP. For example, we saved our index.php in the C:\work\apress\htdocs directory, the directorywe specified for our virtual host. Open a web browser and navigate to the page you just created. You should see a page like the one shown in Figure 8.

Venlon 4.3.4

System W1nllows NT DARKElF 5.1 budd 2600 EUldDa1e Nov 2 2003 23:43:42 5erverAPI Nlache 2 0 Handlet VlrtuallJlrectort SUpport enabled

COOfiglntion ,de ~jni) PlIth C:\WlNDOWSlphp.ini PHPAPI 20020918 PHP Extension 20020429 land Extension 20021010 OebugBuikl no Thread Safely enabled RegIstered PHP Streams Ptlp III1P. IIP, compress.zJlb

Figure 8. PHP 4.3.4 installed on a server

482 Setting Up Your Environment

In the example shown in Figure 8, you can see that PHP is working correctly, the virtual host has picked up the page from the correct directory, and because we left off the filename from the URL, the DirectoryIndex directive we used to specify index.php as a page is also working correctly. Hyou scroll down the page, you should also find that there is a section for the GD module, showing the version and which file types it supports (ifyou followed our suggestion to add the GD module).

Installing and Configuring MySQL

The database server that we will be using is MySQL. MySQL is the most popular open -source database available. Not only does it perform weIl, but it is also easy to install. Other open-source alternatives may perform better, but because of MySQL's market share, you will find a large number of tools and technologies that support MySQL.

HP If you are intere ted in an alternative to MySQL, take a look at Postgre QL, which i also open source but a Iittle trickier to in tall and configure under Windows. When PHP 51aunches (if it hasn't a1ready- the developers are on the last Release Candidate before it get relea ed), you may al 0 want ro inve tigate the option of QLite, which i a uper-fa t, file-ba ed QL engine. You won't need to inseaLl a erver to u eie, because all of the data is file-based, and a1l of the QL functionality is built into the exten ion module.

Downloading MySQL

The latest stable version ofMySQL is version 4.0.15. You can also download MySQL version 4.1, but this version is not yet stable for production environments, so use at your own risk. MySQL is available for practically every platform, and migrating MySQL data­ bases from one platform to another is straightforward. You can get the MySQL installation files from the MySQL web site at http://www.mysq1.com. Navigate to the downloads section, and then select the version that you want to download. Don't select the Debug or Max builds, because they contain code that you don't need for this book. You will then be presented with an option of different mirror sites. Be sure to choose a mirror site that is dose to you and your ISP-the MySQL 4.0.15 installer is 20MB!

483 Appendix

Installing MySQL

Once you have downloaded the installation archive, which for MySQL 4.0.15 under Windows is mysql-4.0.15-win.zip, follow these steps:

1. Extract the contents ofthe archive into a temporary directory.

2. Browse to that directory and double-dick the SETUP.EXE file.

3. When the installer starts, you will be presented with a welcome screen. Click Next to see the information screen.

4. The information screen tells you that ifyou instalI MySQL in a location other than the default C: \mysql directory, you will need to create a special configuration file that tells MySQL where the databases are located. ClickNext.

5. The next screen allows you to select the destination folder for the instal­ lation. Leave this as the default C: \mysql and dick Next.

6. The next screen asks you to select the type of installation that you want. Leave this as Typical and dick Next to begin the actual file installation process.

7. Once the process is complete, dick Finish to complete the installation.

This procedure installs the files that MySQL needs to run.

Starting MySQL

To start MySQL manually the first time, browse to the C: \mysql \ bin directory and double-dick the file winmysqladmin.exe. This will bring up the WinMySQLAdmin screen and start the MySQL server. The first time you run the WinMySQLAdmin program, it will pop up a Quick Setup dialog box that prompts you for a username and password to use. Enter a username and password, and the WinMySQLAdmin program will create this username and password for you. As so on as the server has started, the dialog box will minimize to an icon in your system tray. The green light shows that the MySQL server is running.

484 Setting Up Your Environment

To shut down MySQL from WinMySQLAdmin, right -dick the icon and choose Win NT > Stop the Service. Then confirm that you really want to shut down MySQL. The icon for WinMySQLAdmin remains in the system tray, but now with a red light. Right -dick the icon again and choose Shutdown this Tool to dose the pro gram. The first time that you run WinMySQLAdmin, it will automatically install MySQL as a service. The next time you start Windows, the MySQL service will already be started.

Configuring MySQL

Before you do anything on your MySQL server, you need to set the root password for the server. By default, this is set to nothing, and this poses a possible security risk to your server. Open a Command Prompt window and change to the C: \mysql \ bin directory by issuing the following command: cd \mysql\bin

Your screen should look like Figure 9.

Figure 9. The Command Prompt window under Windows XP

Then type the following command: mysqladmin -uroot password newpassword where newpassword is the new password you want to give to the root user.

485 Appendix

Testing the MySQL Server

Ifyou managed to change the password of the root account without getting an error message that you could not connect to the MySQL server, your MySQL server is up and running. If you did not connect to the MySQL server, make sure that it is running (you should see the green light icon in your system tray). You can use the mysql command-line tool (MySQL Monitor) to connect and query the server. Within the C: \mysql \ bin directory, issue this command:

mysql -uroot -p

You will be prompted for a password. Enter the root account password you set, as described in the previous section. The -uroot option tells MySQL Monitor that you want to use the root account to log in, and the -p option tells it to prompt for the password. Once you have entered your password, you will see the MySQL Monitor to ol welcome message and be presented with the mysql> prompt:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 to server version: 4.0.15-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

At the mysql> prompt, you can enter any of the commands that MySQL Monitor understands, as well as enter any valid SQL to query and modify your databases. The MySQL Monitor program can handle multiple-line commands, so in order to tell it that you are at the end ofyour command, end the line with a ; character. Enter the following command:

show databases;

You will see a list of the currently running databases:

mysql> show databases; +------+ I Database I +------+ I mysql I test +------+ 2 rows in set (0.00 sec) mysql>

486 Setting Up Your Environment

The mysql database is the database that contains all of the usernames and passwords for your installation, as weIl as the permissions that those users have on the various databases. The test database is an empty test database that you can use for testing. To exit MySQL Monitor, enter the following command: exit;

This will return you to your command prompt, where you can type exit again to dose the window.

Setting Up in a Mac OS X System

Apache is installed in Mac OS X by default, so all you need to do is start it, although if more than one person uses your computer, you may want to configure it to start Apache automatically for everyone. PHP is also installed by default, but we recommend that you use a more fully featured version and change the configu­ ration so that error messages are displayed on screen. MySQ L is not part of the standard setup, but it is easy to instalI. Each stage requires digging under the familiar Mac graphical user interface, but it's not difficult. Ityou follow the instructions presented here, you should be up and running quickly. In fact, the longest part of the process is likely to be down­ loading the Mac packages for PHP and MySQL. You will need to make minor changes to certain configuration files using a utility called sudo. This utility can be invoked only when logged into the Mac with Administrative privileges, so make sure you are logged in appropriately before starting.

Starting Apache on Mac OS X

To start Apache on a Mac OS X system, open System Preferences and select Sharing, which is under the Internet and Network section, as shown in Figure 10.

487 Appendix

Show All L-_ Display>_ •. _ .,_.__ Sound •• __" •• •.• WO'"••• _. StO/1Up ._,_,_ 0. •• •••• ______Personal , b I..=.. AppearOlltt 0..1001' $ Doc' Ex_e lnttmatlon-' SeC.,I.,. Scree.n SaYti"

Hardware 0 11 ••1000h CO." OVOS 0..010'" Entrgy ~rd' PT lnl' rax Sound ~r """' .. Internet & Networlt ca .M.tc ~twon: Qulcl

Adobt \'e.nlon CLlt!""

Figure 10. Apache is preinstalled, but must be turned on by the user. You enable it through the Sharing preferences.

Next, dick the Services tab, and then select Personal Web Sharing, as shown in Figure 11. That's all there is to it! Apache is now running. Whenever you make any changes to your PHP instal­ lation, you need to come back to this panel to stop and restart Apache. Use the Stop button shown on the right of the figure to shut down Apache, and dick it again when it displays Start. If you are the only user of the machine, Apache will start automatically each time you boot the computer. If that applies to you, you can now instali PHp, as described in the "Installing PHP" section.

488 Setting Up Your Environment

Compurer Name: Davld Power~' Compuler

Othcr com~ttrS on YOU' lot.1 subnct (an reach you.r ~ «>mp<.t'Ol' .. Oovid- _,,- ComputerJoc>' ~

I Savtces Firewall Inlemel

SeI,CI a service to change i\s senlngs.

On Strvlc~ Personal Web Sharing On Personal File Sharinll o ( SIOP ) Windows Sharing C l k~ Stop '0 "'.-. us." or otIItr [omPU(HS from Icc.~ulng Web pilgu In th-e. Remote Logln iitu fotdrn on ttrh computH". FTPAccess Appl. Rem OIe Desktop RemoIe Apple Event. Printer Sharing

VI ... ,hb ,omPUltr ' ~ ...bs~ ... hllll.il19Z.l.6I..l.HJ or you' penonll ...bo lte .t IPJ.J 19Z.1§8.1.14/.- • ~DI

Olck the locX (0 prevent funher changes.

Figure 11. When you select Personal Web Sharing, Apache immediately starts up.

Conjiguring Automatie Apache Startup Jor Multiple Users

If there are multiple users on your machine, you may want to start Apache for all users when the computer boots. To do this, you must alter the hostconfig file. And to make changes to this file, you use the Terminal program. If you've never used Terminal before, don't panic. It's the interface to the Unix that underlies Mac OS X. There are built -in safeguards to prevent you from changing vital parts ofyour system accidentally. As long as you follow the instructions and take reasonable safeguards, such as backing up files before changing them, you should be quite safe.

489 Appendix

Follow these steps:

1. Open a new Terminal window by opening Finder and selecting Applications ~ Utilities ~ Terminal.

2. Make a backup copy ofhostconfig. Because it's a system file, you must first assume "superuser" status with the sudo command. Type the following command into the Terminal window (make sure you copy it exactly before pressing Return):

sudo cp /etc/hostconfig /etc/hostconfig.original

HP When ryping filename in Terminal, you can ger the shell (the command-line interface) to do ome ofthe hard work for you by pres ingTab after ryping the fir t few character . If there's ju tone file with a name that begin like that, the h 11 will complete the name for you. Ir there i more than one, the shell will beep. Pre sTab again, and you are presented wirh a Ii t of all pos ibil itie .

3. Enteryour password. Nowyouhave a backup copycalledhostconfig.original, ifyou ever need to go back to it.

4. You now need to open the original in a suitable text editor, such as pico. Type the following:

sudo pico /etc/hostconfig

5. Look for this line:

WEBSERVER=-NO-

6. Change it to the following (see Figure 12):

WEBSERVER=-YES-

490 Setting Up Your Environment

Terminal - pico - 80,,24

1'1' ;:1 . " r r 1 ". .... ," ,f 1 1

• Servtce: .t.f'PSER\IER~ 1oIJTHSV!YER~ AUToro..t

Figure 12. Working inside the pico editor to change the hostconfig file

7. To save your changes, press Control-X and select Yes (by pressing Y). Then press Return. You have now configured Apache to start at boot for all users.

If you ever need to res tore the original hostconfig file, simply reverse the process. Type the following: sudo ep /ete/hosteonfig.origina1 /ete/hosteonfig ep is the Unix command for copying a file. It takes two arguments: the file to be copied (with the correct path to the file) and the name of the copy. If there is no path in the name of the copy, it will be stored in the folder (or directory, to use the correct Unix terminology) you're currently working in. When you log in to Terminal in Mac OS X, you automatically work in your horne folder, so unless you change directory, that is where any files will end up if you forget to add the full path to the name of the copy. Unix is case-sensitive; type everything in lowercase, unless you are given instructions otherwise.

491 Appendix

Where to Locate Your PHP Sites on Mac OS X When building static web pages, it doesn't matter where you store your files. Ordinary (X)HTML pages can be viewed in a browser directly from any file on your hard disk or peripheral device. Dynamic pages are different. They must be served up by a web server, such asApache, and the server needs to knowwhere to find them. The way Apache is set up on OS X provides each user account with its individual web horne directory called Sites. This is in each user's horne folder (the one bearing the user's name). Whenever instructions refer to your web server's "Document Root," you should regard it as meaning this Sites folder. (The actual Document Root is elsewhere, but the way Apache is configured means you never need to access it.) Whenever you build a new site, create a subfolder in Sites. This subfolder serves as what is known as the site roat [alder, and this is where you should browse to when defining a new site in Dreamweaver MX 2004. H's also referred to by Dreamweaver as the testing server [alder. To view any pages in one ofyour sites, use http://localhostl followed by a tilde n and the name of your horne folder, another forward slash, and the name of the site root folder. So, ifyour horne folder is called joesoap, and you want to view index.php in a site called apress, the URL would be as follows:

http://localhost/-joesoap/apress/index.php

Installing PHP on Mac OS X

Mac OS X also comes with PHP preinstalled. The version of PHP you have will depend on when yom version of OS X was installed. The way to check is to create a text file in the Sites folder of yom horne folder. Type the following line of code inside the file:

<7php phpinfoO; 7>

Save the file as test.php, making sme that yom text editor does not save it as Rich Text Format (RTF), or add a .txt extension (hidden or otherwise) to the filenarne. Ifyou're using TextEdit, choose Format> Make Plain Text (Shift-Command-Tl. When you save the file, choose Don't Append, as shown in Figme 13.

492 Setting Up Your Environment

Save As: tUl.php 0

@::8! j§ UD ;: ..., Sites :!

S

( YJlcel ) ( 000'( AP~ 'i{) \

Figure 13. Da natappend a .txtfilenameextensian anyaur test PHP page.

If you have started Apache as described in the previous seetion, open a browser and put the following address in the address bar, substituting your own username but retaining the tilde (-): http://localhost/-username/test.php

You should see a page similar to the one shown in Figure 8 in the Windows installation section. Check the PHP version number at the top of the page. If it's version 4.1.1 or later, you have the minimum required to work with Dreamweaver MX 2004, so you can skip to step 4 in the following instructions. However, consider that PHP is constantly under development, improving all the time. It also offers many optional features. The version 4.1.1 or later preinstalled on Mac OS X covers all your needs for this book, but ifyou would like the most up-to-date version with a wider set of features, you can do one of the following:

1. Compile your own version from the PHP source code. Since the release of PHP 4.3, compiling PHP from source on Mac OS Xhas become relatively straightforward for anyone with Linux or Unix experience. If that applies to you, the instructions at http://developer.apple.com/internet!opensourcel ph p. html should tell you all you need to know. If you are compiling from source, set the path to MySQL in the PHP configuration options to /usr/ local/mysql. Once you have completed the installation and copied php.ini, skip to step 4 in the following instructions to make the necessary changes to the main PHP configuration file.

2. If the prospect of compiling from source sounds too daunting, or ifyou have a broadband Internet connection, you may want to follow the lead of many PHP enthusiasts on a Mac by using the installer package created by software engineer and Mac fanatic Mare Liyanage. Be warned, though­ it's a 27.1MB download, five times the size ofthe source code.

493 Appendix

Ityou have version 4.1.0 ofPHP or earlier, you mustupgrade using one of these methods. Here, we present the steps for installing Marc Liyanage's package. At the time ofwriting, the package is for PHP 4.3.4. It has many extensions enabled:

• The PDFLib PDF library, which allows you to create PDF files on the fly, either through user input or directly from a database

• The GD image creation library, which is a powerful set of applications that allow you to create and alter images dynamically

• The expat XML parser and Web Distributed Data Exchange (WDDX) support, which enable you to handle XML files and web syndication using WDDX

• XSL Transformations, a technology that enables you to trans form XML files into (X)HTML or other XML files

• The IMAP dient library, which supplies PHP with an interface to lMAp, an alternative to the POP3 email protocol

• XML-DOM, an extension that offers better XML support than the default libraries bundled with PHP

• PEAR, the PHP Extension and Application Repository, a collection of open­ SOUfce dasses that greatly simplify many complex operations

At this stage, this list may seem like little more than alphabet soup, but it's a rich set of extensions that will be at YOUf fingertips. What's more, installation is a breeze and can be done in a few steps.

1. Download the latest release from Marc's site: http://www.entropy.ch/ software/macosx/php/.

2. When the download is complete, the .dmg file will automatically mount the contents on YOUf desktop, as shown in FigUfe 14. The Extras folder contains the PDFLib library. This requires separate installation, as weIl as the pUfchase of a license, so it will not be covered here. Copy the Extras folder to YOUf hard disk, and read the induded documentation if you want to explore it at a later date. All we are interested in at the moment is the .pkg file (php-4.3.4.pkg in the figUfe). Double-dick it, and then follow the instructions on screen.

494 Setting Up Your Environment

Onl ne­ Oocumentatlon.html

Figure 14. The PHP paekage for Mae OS X ereated by Mare Liyanage

3. Hyou want to keep the .pkg file, drag and drop it into one ofyour folders in Finder. Then drag both Entropy icons onto Trash.

4. Your new version of PHP will be available the next time you reboot or restart Apache as described in the previous section. Before doing that, though, you need to make a slight adjustment to the PHP configuration file, php.ini, to ensure all error messages are displayed if there is a problem with your PHP script. Changing php.ini requires "superuser" status, so you need to make a backup and edit it with pico (or a similar text editor). First, use Terminal to make the backup. (See the "Configuring Automatie Apache Startup for Multiple Users" for more information ab out making backups.) Open a Terminal window by choosing Applications > Utilities > Terminal. Then type the following:

sudo cp /usr/local/php/lib/php.ini /usr/local/php/lib/php.ini.original

5. Enter the following command to start pico with php.ini loaded:

sude pico /usr/local/php/lib/php.ini

6. When pico opens, you'll see that php.ini is more than 1,100 lines lang. Most of this consists of comments, but what you're interested in is one of the configuration commands on a line of its own. It's best to use pico's search facility by pressing Control-W. Your cursor will jump to a Search prompt, as shown in Figure 15. Enter the following command:

495 Appendix

8 00 Te rm ln ~ l - pico - 80x24 i!I

[PlI']

.....·'f."_"""",...... , ,1. ; About Ull. rl I. ; ...... " .. , ...... '." . ; Thl. 10 U>e r...-nded, PlI' 4-otyl. 'ler_lon of Ulo p/"c).lnl-er you want to uso It or not.

; For

; Thl. fll. I. different fre. Ulo p/"c).lnl-

Get HelP 1 dtrstL tne I"·"rConoel Lo_tLlne

Figure 15. Using pico's search facility to find display_errors in php. ini.

7. When you press Return, the cursor jumps to the first instance. Repeat the search three more times, and you should find the command you are looking for on a line of its own:

disp1ay_errors Off

or

disp1ay_errors On

NOTE A developmem server should a1ways have error reporting turned to the highe t level, 0 you can see immediately when omething goes wrong. e Chapter 8 for more details of tracking down and correcling error .

8. If necessary, change the setting to On, as shown in Figure 16. Also check that the line beginning errar_ reparting (seven lines up) is the same as in the figure. If not, change it to read as follows:

496 Setting Up Your Environment

Terminal- pico - 80)(24

't .:1 • \, r r 1 .. . j': I, 1 .1'1 j \ ' I " lr'l

, ; - Show oll erron

; Prlnt out errors (os 0 port 01 t.IIe output). For proooction web .Iw, ; you're stl'on9ly encouroged to wm thls leowre alt, end use error IOQIII"!/ ; Inst.eod (see bei"")' Keepl"!/ dlaplGy_orrors enabled on 0 prOduetlon web olto ; oooy reveol secur lty InlorllOtlon to end users, such 0' 1110 path. on your 11th i server , your dotabm:e scheea or other tntoTlKItton . " SJ>IGy_error•• On

i Evon vhen display_enon 1, on, orron thot. oocur durtng Ptf"'s stortup ; sequence or. not dltployed. It's otrO"!/ly roc:o.ended to 1

Get Help I Wrtt~t - File . Pr .... I'Q Elelt Justlly Whor. h Hext I'Q

Figure 16. The correct PHP settings for errar reporting on a development computer

9. Press Control-X to exit pico, and save the changes to php.ini. Your PHP installation is now ready, so restart Apache as described in the previous section.

TIP Ifyou get lost at any tage when u ing pico, pre ontrol-G for help, or pre s Control-X and di card any change by electing , follow d by Return. Then start aJl over again.

Installing MySQL on Mac OS X

Follow these steps to download and install MySQL on a Mac OS X system:

1. Go to the MySQL downloads section at http://www.mysql.com/downloads.

2. Select the link for the production release of MySQL database server and standard clients (MySQL 4.0 at the time ofwriting). Scroll down to the Mac OS X downloads section and choose the Standard Installer Package.

497 Appendix

3. When the download is complete, the .dmg file will automatically mount the contents on YOUf desktop in the same way as for the PHP installation. There should be three files: ReadMe.txt and two .pkg files. Double-dick the mysql-standard-4.x.x.pkg icon to start the installation process (the precise name of the file will depend on the version downloaded). This opens the Mac OS X installer. Follow the instructions on the screen.

4. Double-dick MySQLStartupItem.pkg and follow the installation instructions on screen. This is a once-only operation. You won't need to reinstall it when upgrading to a later version of MySQL.

5. You can now discard the .pkg and .dmg files, although it's a good idea to keep the ReadMe. txt in case of problems. The quickest way to make SUfe Apache, PHp, and MySQL are running is to reboot YOUf computer.

All you have left to do now is change the MySQL root password, the instruc­ tions for which are the same as under Windows. See the "ConfigUfing MySQL" section earlier in the chapter for details. Also, you can make it easier to use MySQL from Terminal by adding it to YOUf PATH, as described in the following section.

Adding MySQL to Your Path

Most of the time, you will access MySQL through Dreamweaver or phpMyAdmin, but there will be tim es you want to use Terminal. To avoid needing to type the full path to the mysql!bin directory every time, you can add it to the PATH in YOUf envi­ ronmental variables. The way you do this depends on YOUf version of Mac OS X. Until the release of 10.3 (Panther), the default Unix shell used by OS X was the tabbed c shell (tcsh). Ifyouhave upgraded from Jaguar to Panther, you will probably still be using tcsh. If, on the other hand, you made a dean instalI, or if YOUf computer came with Panther already instalied, you will be using the bash shell. The way to tell is to look at the title bar of a new Terminal window. It should display either tcsh or bash, as shown in FigUfe 17. Type the command appropriate for YOUf shell.

498 Setting Up Your Environment

6 00 Terminal - bnh - 80x24 Lost l"'lI": __ 17 19:22:29 on COIlS<)le ""la- to 1lonI1"1 YlljOrti:- davldpovers$ pico -I.proflle.

Figure 17. The title bar ofTerminal identifies wh ich shell you are using.

To set the path for the tcsh shell, enter the following: echo 'setenv PATH /usr/local/mysql/bin:$PATH' » ~/.tcshrc

If you have the bash shell, you need to edit your profile file in a text editor, such as pico. First, type the following to open pico: pico ~ / . profile

Then move your cursor to a new line following any content (although it may be empty) , and enter the following line of code, as shown in Figure 18. export PATH="$PATH:/usr/local/mysql/bin"

Finally, save the file.

499 Appendix

Term naJ - pico - 80x24

export PATHo'$PATl1 : /USr/(ocoll~(Ib(n' l

Reoa ft (e I Prev P9 I CUt Text 11 CUr Pos _re I. Next P9 lroCUt TextJil To Spe((

Figure 18. Setting the pathfor MySQL in the bash shell (Panther)

Setting Up Dreamweaver MX 2004

The environment within which we will be doing everything in this book is Dream­ weaver MX 2004. This next section covers some of the basic things that you will need to do to get Dreamweaver MX 2004 up and running.

Dreamweaver MX 2004 7.0.1 Updater If you bought Dreamweaver MX 2004 before March 11, 2004, you should install the 7.0.1 updater from Macromedia. The updater not only improves Dream­ weaver performance dramatically, but the Mac OS X version fixes a serious bug that prevented Dreamweaver from creating recordsets. Although there is a sim­ ple workaround for this bug, the updater makes such a major difference, it's not worth describing the solution here. Even if you bought YOUf copy after March 2004, you should still check YOUf version. It appears in the bottom -right corner of the Dreamweaver logo screen as the program starts up. Or to check YOUf version from within the program, on Windows, choose Help > About Dreamweaver; on the Mac, choose Dreamweaver > About Macromedia Dreamweaver MX 2004. On both platforms, dick the rolling credits screen, and the version number appears. If it's not 7.0.1 or higher, get the free updater from Macromedia at www.macromedia.com/ support/dreamweaver/downloads/downloads_updaters.html.

500 Setting Up Your Environment Downloading and Installing Dreamweaver

If you do not yet own Dreamweaver MX 2004, you can download the trial version from the Macromedia web site. Open a web browser to http://www.macromedia.com and select the link to Free Trials and then dick through to the Dreamweaver MX 2004 Trial (http://www.macromedia.com/go/trydreamweaver). You need to be signed in to the Macromedia web site to download any trial versions, so if you are not already signed up, create a new Macromedia password. When you create a new password, you must provide some information and partake in a short survey. After you are signed in, you will be able to download any of the Macromedia trial versions, download extensions for Dreamweaver, and access the community areas on the Macromedia site. After signing in, you will be prompted to select the version ofDreamweaver to download. Depending on the language and version that you want, the download size will vary from 55MB to 105MB. The English version for Windows is 99MB, and the Macintosh version is 87MB. Once you have the Dreamweaver installer downloaded, follow these steps to install the application:

1. Double-dick the installer to start the installation.

2. After the necessary installation files have been extracted, you will be pre­ sented with the installation welcome screen, as shown in Figure 19. Click Next, and then dick Yes to agree with the License Agreement.

3. The next screen allows you to select the destination folder for the instal­ lation for Dreamweaver. Click N ext to accept the default of C: \Program Files \Macromedia \ Dreamweaver MX 2004.

4. The next screen allows you to select which document types to associate with Dreamweaver. For example, if you are also a and you would rather use a product like Borland JBuilder to edit your JSP pages, deselect the option to associate JSP files with Dreamweaver.

5. Click Next. You are given a last chance to reviewyour installation settings before the copying of actual files begins. If you are satisfied with the settings you have chosen, dick Next to begin the setup. A progress bar informs you of the setup status, as shown in Figure 20.

6. When the installation is complete, dick Finish on the last screen to complete the installation.

501 Appendix

Macromed'il Dreamweilver HX 2004 Installation 'A~ )(

\tIelcome 10 lhe Ins laliShield \tIizald 101 Nacromedia D,eamweave, NX 2004

The InstaJIShiekJe W"lZilrd will instaß Macromedia Dreamweaver MX 2004 on yolJl compulel. To contirue. ctick Next.

macromedia MX

Next > Cancei

Figure 19. Starting the Dreamweaver MX 2004 installation

i'lacromedla Dreamweaver MX 2004 Installation .1x S elup S lalul macromecia'~

Macromedia Dleamweave! 2004 Setup 1$ pefformi1g the lequested operations.

5"

In~)nS~~d------1

Cancel

Figure 20. Dreamweaver busy installing

502 Setting Up Your Environment Starting Dreamweaver MX 2004

You can now start Dreamweaver MX 2004 by choosing Start> Programs > Macromedia> Macromedia Dreamweaver MX 2004. When you first start up Dreamweaver, you will see the Workspace Setup dialog box, as shown in Figure 21. Dreamweaver wants to know how you would like your workspace to look. The Designer option (the default) includes the palettes and menus for adding content to your page in a WYSIWYG (What You See Is What You Get) environment. The Coder option sets the environment up in a way that is more conducive to writing your own code. The screenshots and explanations in this book assume that you have Dreamweaver set up to use the Designer-style workspace.

Workspace Setup "p!,

Please choose lhe workspace layout you Plefer. You can switch layouts laler in Preferences,

r. Designer r Coder

OK

Figure 21. Selecting a workspace layout in Dreamweaver

Ifyou have installed a commercial version ofDreamweaver MX2004, you will be prompted for your serial number. If you have an earlier version of Dreamweaver MX instalied, Dreamweaver will re-create the site cache to be compatible with Dreamweaver MX 2004. With your web server, PHp, MySQL, and Dreamweaver up and running, you're ready to get started with developing your web sites. You will be able to follow the examples in this book.

503 Index

Symbols balancing, 310-311 -- (decrement operator), description of, 17-18 placement of, 375-376 - (subtraction operator), description of, 17 significance of, 308 ! (logical Not operator), description of, 20 11 (logical Or operator) != (not equal operator), description of, 20 description of, 20 !== (not identical operator), description of, 20 example of, 23 $ (dollar sign) + (addition operator), description of, 17 significance of, 8 ++ (increment operator), description of, 17-18 in strings, 12 < (less than operator) using with variables, 299 converting with htmlspecialcharsO in variable expansion, 10 function, 318 \$ escapable character, description of, 12 description of, 20 % (modulus operator), description of, 17 , & (ampersand) , converting with significance of, 275 htmlspecialcharsO function, 318 <= (less than or equal to operator), && (logical And operator), description of, 20 description of, 20 o (parentheses), importance to includeO <> (angle ), problems associated and requireO methods, 237 with,317 * (multiplication operator), description of, 17 = (assignment operator), example of, 18-19 . (concatenation operator) == (equal operator), description of, 20 example of, 18 === (identical operator), description of, 20 significance of, 299 > (greater than operator) .= (concatenating assignment operator), converting with htmlspecialcharsO example of, 330 function, 318 / (division operator), description of, 17 description of, 20 / / (slashes), significance of, 7 >= (greater than or equal to operator), /* and */, commentingwith, 335 description of, 20 /* (slash-asterisk), significance of, 7 , (apostrophes), escaping in user input, 317

?: (conditional operator), example of, 335 n (double quotes) @ (error-suppression) operator, using, 321 converting with htmlspecialcharsO @@(Home)@@parameter, explanation of, 215 function, 318 [] (brackets), using with arrays, 14-15 escaping in user input, 317 \ \ escapable character, description of, 12 using with arrays, 409 _ (underscore), using with variables, 8 using with string variables, 10-12, 307 , (backtick) , purpose of, 397 using with strings, 307 {} (braces) using with XHTML, 87-88

505 Index

\ n escapable character, description of, 12 administration files, overview of, 354 ; (semicolon) Administration privileges in phpAdmin, including, 299 description of, 46 significance of, 4, 12,308 administration section in SQL, 55-56 adding new members to, 365-381 using with MySQL commands, 32, 41 attaching stylesheet for, 355 , (single quotes) controlling committee and converting with htmlspecialcharsO membership categories in, function, 318 356-365 using with string variables, 10,307 setting up site for, 353 administrators, building page for addition and deletion of, 405-407 A aliases, creating for Apache on Windows tags, selecting, 214, 216 systems, 472 absolute positioning, absence of, 144 all media descriptor in CSS2, explanation access control, resource for, 355 of,148 accessibility, improving with CSS, 97 allcds.php page, creating and saving, 197 Accessibility page, options on, 96 allow_urLfopen remote server, action attribute, setting for feedback form, relationship to include files, 237 448-449 ampersand (&), convertingwith Add a new User page, displaying in htmlspeciaicharsO function, 318 phpMyAdmin, 43 AM/PM signifier, adding check box for, 269 addArticie form, contents of table in, 398 anchor tags, styling, 141 addarticle.php page, description of, 354 angle brackets «», problems associated addition operator (+), description of, 17 with,317 addmember.php page anonymous access, removing, 325 creating, 365 Apache web server description of, 354 configuring for Windows systems, previewing, 370 468-475 testing, 376 configuring to use PHp, 479-480 validation settings for, 372 downloading for Windows systems, 461-462 AddNewMember form installing on Windows systems, contents of table in, 366 462-466 creating, 365 restarting and testing installation on address information, handling, 350 Windows systems, 481-483 addslashesO function, example of, 317 setting up default environment on addUser form, creating, 405-406 Windows systems, 471-475 admin folder, securing, 405-415 setting up global environment on admin table in Roundtree Garden Club Windows systems, 469-470 case study, building structure for, starting and testing on Windows 352-353 systems, 466-468 admin. file, contents of, 355 starting on Mac OS X, 487-491

506 Index

API (application programming interface), artist table creating extensions with, 256-257 adding fields to, 155 apostrophes C), escaping in user input, 317 assigning primary keys to, 154 apress database artists, listing, 170-174 connecting to, 157-159 assignment operator (=) creating with phpMyAdmin, 40-41 confusing with equality operator, Apress site, creating with Dreamweaver MX 327-328 2004, 72 example of, 18-19 apress user, creating, 53 explanation of, 16-17 apress username, specifying in associative arrays, overview of, 15-16 phpMyAdmin,43 Attribute {} errors, solutions for, 131 archive directory, creating in htdocs attribute minimization, relationship to directory, 353 XHTML,90 arithmetic operators, overview of, 17-18 attribute names, case-sensitivity in arrayO constructor, example of, 14 XHTML,88 array values, troubleshooting, 329-331 attribute va!ues, enclosing in quotation array_wa!kO function, resource for, 339 marks, 87-88 array.php page, creating, 329 Attributes column in MySQL arrays description of, 50-51 functions for sorting of, 401 filling,52 overviewof,14-16 attributes, modifying, 217. See also editable testing for, 337 attributes using in Roundtree Garden Club case aura! media descriptor in CSS2, study, 374 explanation of, 148 using quotes with, 409 authentication article.php page, building, 430-433 setting for admin folder, 411-412 articles setting in phpAdmin, 36-37 adding, 398-402 authormenu editing, 403-405 building for editarticle. php page, 404 listing, 402 populating in articles, 399 articles table in Roundtree Garden Club Auto Indent feature, making code more case study readable with, 308-309 building structure for, 350-352 auto_increment option in MySQL, contents of, 344-345 explanation of, 51 articles.php page, displaying full articles AUTO_INCREMENT, using with members on, 427-434 table, 348 artist information deleting, 188-190 B editing, 186-188 and versus and , filtering, 177-179 significance of, 95 artist link, previewing, 179 background color, setting with CSS, 121 backtick Cl, purpose of, 397

507 Index

Balance Braces feature, using, 310-311, button icon, adding to extensions, 274-275 375-376 buttons, controlling down state of, 214 .banner dass, creating, 121 #banner file, creating, 135 c banners cascading deletes, controlling, 359 creating with CSS, 135-137 case statements, using with switch creating with Dreamweaver, 118, 121 statements, 23-24 basic template, creating, 207 case study. See Roundtree Garden Club behaviors case study applying to library items, 225-226 CatDel form, creating, 357 using extensions with, 263-264 categories.php page Behaviors panel, removing behaviors creating, 356 with,298 description of, 354 Bindings panel, using, 435 improving, 393-396 blank.mxi file, code for, 290-291 purpose of, 358 blank-screen error, troubleshooting, 300 category administration page, categories BLOB field type, explanation of, 49 addedto,364 block quotes, advisory about using for category recordsets, settings for, 367 indentation, 92 category table in Roundtree Garden Club

elements, adding and case study removing, 109 building structure for, 347 Boolean variables, overview of, 13 contents of, 344-345 border= "0" attribute, meaning of, 133 deleting records from, 362 borders Insert Record settings for, 361 adding to banners, 121 CD information adding to navigation list items, 141 filtering, 179-182 removing from images, 131-132 setting up for modification of, 190-194 braces ({}) updating and deleting, 194-196 balancing, 310-311 CD names, storing, 154 placement of, 375-376 CD recordset, setting up, 191 significance of, 308 CD report brackets ([]), using with arrays, 14-15 inserting table for, 198 braille media descriptor in CSS2, setting up table for, 199 explanation of, 148 cd table break statements, using with switch assigning primary keys to, 154 statements, 23-24 inserting records from, 184 browser and device issues, addressing, 145-149 CD title information, adding, 183-185 browsers CDATA tags, using to package extensions, 292 echoing output to, 334-335 cd.php page, creating and saving, 191 managing with Dreamweaver MX 2004, CDs in database 69-70 creating statistic for, 162-164 ordering by artist name, 197-199

508 Index cell height and width, setting in Property code sections, converting into library inspector, 120 items, 222-223 cells, centering in Dreamweaver, 122 Codeview CHAR field type, storing text in, 48-49 adjusting default font for, 310 character entities, using for special avoiding syntax errors with, 304-309 characters, 94-95 switching to, 36 characters. See also special characters working in, 297 converting with htmlspecialcharsO colname variable, defining for function, 318 article.php, 430 dealing with in user input, 316-318 Color drop-down menu in Dreamweaver, Check Browser feature in Dreamweaver MX advisoryabout, 109 2004, benefits of, 69-70 color scheme, setting for script elements, 307 Check Form MX validator, downloading, 371 column names, advisory about, 351 check in/ check out system, using in columns Dreamweaver MX 2004,77-78 adding to existing tables, 439-441 Check Links Sitewide feature, using in addingto SQL, 193 Dreamweaver MX 2004,80-81 limiting in INSERT statements, 54 child pages selecting for recordsets, 170, 172 creating from templates, 211-2l3 selecting in recordsets, 173 detaching from templates, 218 Command Prompt window editing areas of, 208-211 opening, 322 explanation of, 207-208 using with MySQL Monitor, 28 identifying, 212 command.htm file, creating, 278 working with editable attributes in, 217 command-line scripting, using PHP for, 3 chmod command, setting directory commands permissions with, 320 executing and splitting with MySQL "Choose which attributes ofthis BODYtag Monitor, 32-34 should be editable" message, gene rating, 214 using extensions with, 258-259, 278-280 classes commas, finding and replacing with creating with CSS Styles panel, 107 nothing, 315 resource for, 306 commenting files, 79-80 C: \mysql \ bin directory, changing to, 29 comments Code blocks, enabling, 281-282 adding,7 code format of, 335 enhancing readability of, 308-309 making code more readable with, saving in Snippets panel, 231-235 308-309 code libraries, building, 226-235. See also committee category, controlling, 356-365 library items committee dynamic drop-down menu, code reuse settings for, 369 with custom-built PHP functions, 228-231 committee list, building, 437-441 significance of, 203 committee recordsets, settings for, 360, 367

509 Index

committee table in Roundtree Garden Club CSS (Cascading Style Sheets) case study for administration seetion pages, 355 building structme for, 346-347 creating banners with, 135-137 contents of, 344-345 creating navigation with, 137-142 deleting records from, 362 implementing, 99-100 Insert Record settings for, 361 improving accessibility with, 97 components, using extensions with, 265 justification for use of, 97-98 CONCAT function, example of, 399 for layout, 134-135 concatenating assignment operator (.=), overview of, 96 example of, 330 placing content area with, 143-145 concatenation operator (.) removing borders from images with, example of, 18 131-132 significance of, 299 resomce for, 423 conditional operator (? :J, example of, 335 setting background color with, 121 config authentication in phpAdmin, setting properties oftable cells with, 133 explanation of, 36 styling pages with, 420-423 Configmation folder using, 100 contents of, 268 CSS classes, creating, 101 location of, 287 CSS editors, specifying in Dreamweaver, 103 connection problems, troubleshooting, CSS files 321-325 creating with Dreamweaver, 117 connections opening in Dreamweaver, 103 creating between web pages and CSS information, online resomces for, databases, 157-159 144-145 selecting, 167 CSS page designs in Dreamweaver, using, Connections folder, uploading, 324 UO-IU constructs versus PHP functions, 236 CSS Panic Guide, web address for, 145 contact page, creating, 448-456 CSS rules content area, placing with CSS, 143-145 advisory about, 103 control structures redefining HTML tags with, 100-101 decisions, 21-24 CSS Style Definition dialog box loops, 24-25 defining borders in, 121 overview of, 21 displaying in Dreamweaver, 106 controls, displaying selectively, 200 CSS styles, creating for navigation, 138 cookies authentication in phpAdmin, CSS Styles page, displaying in explanation of, 36-37 Dreamweaver, 102-103 cp command, effect of, 491 CSS Styles panel Create a New Code Block dialog box, attaching stylesheets with, 107-108 displaying, 282 creating classes with, 107 CREATE TABLE command, example of, creating new stylesheets with, 104-106 52-53, 156 editing styles with, 106

510 Index

CSS stylesheets selecting and ordering for reports, attaching for administration section, 355 197-199 attaching in Netscape 4, 145 selecting with SQL, 56-57 attaching with CSS Styles panel, updating with SQL, 57-58 107-108 data checks, co ding for admin folder, creating with CSS Styles panel, 104-106 407-411 displaying at design time, 112 Data privileges in phpAdmin, description in Dreamweaver, 109-110 of,46 using prebuilt CSS in Dreamweaver, data sources, using extensions with, 265 109-110 data translators, using extensions with, 266 using with media descriptors, 148-149 database connection problems, CSS tools in Dreamweaver MX 2004 troubleshooting, 321-325 CSS Styles panel, 104-108 database information design files, 109-111 editing and deleting, 186-196 design -time stylesheets, 111-112 reporting, 196-201 integration with TopStyle CSS editor, database main screen, navigating to, 156 112-113 database page, displaying in Page Properties dialog box, 109 phpMyAdmin, 38 preferences settings, 102-104 database password problems, troubleshooting, 325-326. See also Property inspector, 108-109 passwords CSS versus tags, 91 database structure, building for Roundtree CSS Zen Garden, web address for, 145 Garden Club case study, 346-353 CSS2 specification, media descriptors in, 148 databases CSS-Discuss, web address for, 144 adding CD tide information to, 183-185 ctte_ID radio button, creating, 357 adding records to, 166 CtteAdd form, creating, 356 building, 155-157 curly braces. See Balance Braces feature; connecting to with MySQL Monitor, 30 braces connecting web pages to, 157-159 cursor position, significance of, 297 creating for Roundtree Garden Club custom-built functions, relationship to case study, 345-346 values, 332 creating with MySQL Monitor, 41 Customize Favorite Objects dialog box, creatingwith phpMyAdmin, 40-41 displaying in Dreamweaver MX 2004, 66 displaying data from, 169-176 normalizing, 153-154 planning for Roundtree Garden Club D case study, 344-345 data and primary keys, 46 deleting with SQL, 58-59 selecting with MySQL Monitor, 30-32 displaying from databases, 169-176 transferring form data into, 371 inserting with SQL, 54-56 using lowercase letters with, 41 manipulating, 53 database-specific privileges, controlling in retrieving with recordsets, 159-165 phpMyAdmin, 45-46

511 Index

data -entry form, building for members in describe command, issuing in MySQL Roundtree Garden Club case study, Monitor, 33 365-372 design files in Dreamweaver date field types, overview of, 49-50 CSS page designs, 1l0-111 date formats prebuilt CSS stylesheets, 109-110 adjusting for members, 390-392 design flexibility, gaining with CSS, 98 specifiers in MySQL, 428 Design Notes dialog box, displaying in storing as snippets, 234-235 Dreamweaver MX 2004, 79 dateO function, example of, 222 Design Time Style Sheets dialog box, date validation, testing in Roundtree displaying, 239 Garden Club case study, 376 Design view dates after inserting table, 115 entering, 230 displaying changes in, 117 preparing for MySQL database, displaying content area in, 143 372-376 displaying navigation area in, 139 reformatting, 399 displaying navigation list in, 140 Dead Can Dance band name, design-time stylesheets in Dreamweaver normalizing, 154 features of, 111-112 debugging techniques using, 240 echoing SQL and output to browser, Detach from Original option for library 334-335 items, explanation of, 224 overview of, 333-334 detail pages, creating, 441-447 using custom-built debugging development time, shortening with CSS, 98 function, 335-339 device and browser issues, addressing, decimal notation, using with integer 145-149 variables, 9 dialog boxes in Dreamweaver MX 2004 decision control structures designing, 289 if statements, 21-23 improvements in, 65-66 switch statements, 23-24 dieO function, explanation of, 323 decrement operator (--), description of, $dims, testing for, 446 17-18 directories, setting permissions on, 320 Default column in MySQL, description of, 33,51 disableCaseO function, adding to PHPTime.js file, 273 default environment, setting for Apache on Windows systems, 471-475 Display Total Records dialog box, displaying, 163 definition lists, guidelines for use of, 94 display_errors setting Delete Record server behavior finding in php.ini, 496 using, 188-190, 196 significance of, 300 using with Roundtree Garden Club case study, 362 DISTINCT keyword, effect of, 396 DELETE statement, example of, 58

tag delUser form, creating, 405 appearance in main area ofpages, 143 inserting for banners, 135

512 Index

inserting for navigation area, 138-139 design files supplied with, 109-111 surrounding with template tags, 210 design -time stylesheets in, 111-112 division operator (/), description of, 17 dialog-box improvements in, 65-70 DOCTYPE declarations, using with downloading and installing, 501-502 XHTML, 86-87 examining workspace in, 62-63 document structure, separating from Favorites panel in, 65 presentation, 97 integration with Macromedia documents, reopening in Dreamweaver Fireworks MX 2004, 66-68 MX 2004, 68-69 integration with TopStyle CSS editor, dollar sign ($) 112-113 significance of, 8 interface changes in, 61-64 in strings, 12 layers in, 135 using with variables, 299 location of, 267 in variable expansion, 10 managing links within sites with, 80-81 DOM (Document Object Model), checking overriding default behavior of, 219 support for, 147 Page Properties dialog box in, 109 double quotes (") Property inspector in, 108-109 converting with htmlspecialcharsO save desktop option in, 68-69 function, 318 setting margins in, 116 escaping in user input, 317 setting page properties with, 116-118 using with arrays, 409 setting preferences for XHTML in, 95-96 using with string variables, 10-12,307 setting preferences in, 102-104 using with strings, 307 setting up sites with, 71-77 using with XHTML, 87-88 starting, 503 down state ofbuttons, controlling, 214 switching to Code view in, 36 Dreamweaver extensions. See extensions validating documents in, 127-128 Dreamweaver MX 2004 validatingweb pages with, 168-169 7.0.1 updater for, 500 Dreamweaver templates, guidelines for use 166 adding forms with, of. See templates adding page content with, 122 Drop tab in phpAdmin, description of, 40 adding table for layout in, 114-115 drop-down menu, creating for members in centering cells in, 122 Roundtree Garden Club case study, check in! check out system in, 77-78 367-370 commenting files in, 79-80 DTDs (document type declarations) creating CSS files with, 117 relationship to XHTML, 85-87 creating layouts in, 118-127 and XHTML Strict, 128-133 creating navigation areas and rollover .dwt extension, explanation of, 207 images in, 122-127 dynamic data creating recordsets with, 160-161 adding to web pages, 170-176 creating XHTML documents in, 113 listing in tables, 170-174 cross-browser validation in, 69-70 setting up for CD information, 183 CSS Styles panel in, 104-108 workingwith, 150-151, 159

513 Index

Dynamic Data dialog box, displaying, 181 elements dynamic drop-down menu, creating for result of embedding incorrectly, members in Roundtree Garden Club 297-298 case study, 367-370 using Syntax Coloring with, 306 dynamic effects, proper removal of, 297 else keywords, using with if statements, 22 Dynamic Text dialog box, displaying, 382 elseif structures, using with if statements, 22 dynamic text, inserting in Roundtree tags, wrapping elements in, 108 Garden Club case study, 358-364, 435 email, sending with PHp, 452-453 dynamic values, inserting for radio embedded stylesheets, implementing CSS buttons, 363 with, 99-100 embossed media descriptor in CSS2, E explanation of, 148 E_ALL PHP constant, advisory about using empty elements, relationship to XHTML, 89 quotes with, 314 $endDate variable, example of, 230 E_NOTICES PHP constant, advisory about ENUM, significance of, 350 using quotes with, 314 equal operator (==), description of, 20 E_USER_ERROR type, significance of, 323 equalityoperators Echo button, advisory about, 298, 300 advisory about, 375 echo construct confusing with assignment operators, example, 222 327-328 purpose of, 4 ERROR 1045: Access denied for user, using with SQL queries, 335 troubleshooting, 325 Edit * options, effect in Dreamweaver MX error messages 2004, 76-77 adding to contact page, 454-456 Edit Privileges page, displaying in co ding display of, 410 phpMyAdmin, 45 controlling output of, 313-315 ediCartist.php page, creating and saving, 186 handling, 299-303 editable attributes. See also attributes suppressing display of, 314 in child pages, 217 $error, testing for, 375 creating in locked areas, 214-216 error_reporting setting, checking, 300 editable regions, renaming, 209. See also errors, identifying, 301-303 noneditable areas error-suppression operator (@), using, 321 Editable Tag Attributes dialog box, $errType, purpose of, 323 opening, 215-216 escapable characters, table of, 12 editArticie form, contents of table in, 398 escapeQuotesO function, example of, 317 editarticle.php page Excel, integration with Dreamweaver MX description of, 354 2004,67-68 overview of, 403-405 Exchange editmember.php page result of searching for extensions with, 251 creating link to, 383 web address for, 249 description of, 354 exclusive OR operator improving, 393 description of, 20 saving, 370 example of, 401-402 514 Index explodeO function, example of, 228, 372 external PHP files, wrapping in PHP tags, 243 Export tab in phpAdmin, description of, 39 external stylesheets, implementing CSS Extension Manager with,99-100 downloading, 247 externals subfolder, saving, 355 features of, 247-249 Extra column in MySQL packaging extensions with, 293 description of, 33, 51 extension modules, configuring in PHp, 479 filling,52 extension types extractFirstO function, effect of, 427 behaviors, 263-264 commands, 258-259 F components, 265 failure.php page, creating in admin data sources, 265 folder,4l3 data translators, 266 Favorites panel in Dreamweaver MX 2004, floating panels, 262-263 adding buttons to, 65 insert bar objects, 258 feedback form, creating for contact page, menus, 259 448-449 property inspectors, 262 Field column in MySQL tables, description of,33 reports, 260-261 field types, overview of, 48-50 server behaviors, 264 fields server formats, 265 adding to artist table, 155 server models, 266 defining for tables, 51-53 tag libraries and tag editors, 261-262 ente ring in phpMyAdmin, 48 toolbars, 259-260 explanation of, 46 extensions mailing contents of, 454 adding button icon to, 274-275 file sizes, controlling with CSS, 98 APIs Capplication programming interfaces) for, 256 File Types/ Editors page, displaying in Dreamweaver, 104 commands, 278-280 files finding for PHp, 249-252 commenting, 79-80 formatting time in, 267 configuring in Dreamweaver MX 2004, 73 insert bar objects, 266-277 copying to package extensions, 290 installing, 252-255 using check in/ check out system with, installing in Extension Manager, 293 77-78 packaging, 289-293 float variables, overview of, 9 reloading, 275-276 floating panels, using extensions with, server behaviors, 280-287 262-263 versus Snippets panel, 247 folders in Snippets panel, naming, 231-232 testing, 276-278 Font drop-down menu in Dreamweaver, using, 255-256 advisoryabout, 109 viewing details of, 252 tags, guidelines for use of, 91 external files, including code from, 236-244 fonts, adjusting default for Code view, 310

515 Index

fopenO setting of 666, overriding, 320 getTheDateO function for loops, overview of, 24-25 code for, 373 Forbidden page, displaying in Apache web operator used with, 375 server, 474 global environment, setting up for Apache foreign key, example of, 157 on Windows systems, 469-470 form data, transferring to databases, 371 global variables, configuring in PHp, 478 form output, debugging, 338 global.css stylesheet, saving, 117 Format drop-down menu in Dreamweaver, GRANT privilege in phpAdmin, description options on, 108 of,46 forms greater than operator (» adding in Dreamweaver, 166, 183 converting with htmlspecialcharsO adding tables to, 268 function, 318 adding to edit information, 187 description of, 20 for deleting artist information, 190 greater than or equal to operator (>=), for modifying CD information, 190-194 description of, 20 with multiple fields, 454 guess.php page, creating, 327 for updating and deleting CD records, Gur applications, using PHP for, 3 194-196 Gutmans, Andi and development of validating, 450-451 PHP 3.0,1-2 Frameset XHTML, characteristics of, 86 FROM_UNIXTIMEO function, explanation H of,50 handheld media descriptor in CSS2, functions. See PHP functions explanation of, 148 element G apparent comments in, 207 garden club case study. See Roundtree deleting extra white space before, 244 Garden Club case study "headers already sent" runtime error, Garden Club PHP site, creating, 353 troubleshooting, 319 gardenclub database, creating, 345-346 heading tags gardenclub folder, creating, 353 redefining style of, 122 gcConn connection, creating in MySQL, 359 using for structure, 91-92 GD image libraries, enabling in PHp, 479 heredoc syntax, using with string variables, 12-l3 Generate Behavior dialog box, displaying, 378 hexadecimal notation, using with integer GET arrays variables, 9 relationship to error messages, 314 hidden fields, assigning values to, 195-196 turning on debugging with, 338 hover state, advisory about setting GET methods, using with associative properties for, 142 arrays, 15 htdocs directory in Windows, using as site getDimsO function, code for, 447 root, 353 GetSQLValueStringO function, using with HTML dialog box, creating for insert bar server behaviors, 316 objects, 267-272

516 Index

HTML files, excluding from interfaces, 275 includeO methods HTML (Hypertext Markup Language), importing XHTML and PHP functions using standards-compliant mode with,237-243 with, 87. See also markup; XHTML using with external files, 236 (Extensible Hypertext Markup increment operator (++), description of, Language) 17-18 HTML links, preventing malicious indentation, guidelines for application of, 92 embedding of, 318 Index column in MySQL, description of, 51 HTML tags. See tags index.php file tags, advisory about locking areas creating and saving, 411 outside of, 220 displaying in Design view, 241-242 htmlspecialcharsO function, characters converted by, 318 and User Authentication server behavior, 416 http authentication in phpAdmin, explanation of, 36-37 index.php page httpd.conffile creating and saving, 157 chan ging in PHP 5,481 description of, 354 sections of, 469 locating SQL queries from, 334 inline stylesheets, implementing CSS with, 99 I tag, opening tag editor for, 270 Insert bar extension, result of, 277 icons, examples of, 442-443 insert bar objects, using extensions with, ID, adding for

tags, l35-l36 258,266-277 identical operator (===), description of, 20 Insert bar, proper use of, 298 if statements Insert Div Tag dialog box, opening, 135 nesting, 452 Insert Parameter In Code Block dialog box, overview of, 21-23 displaying, 283 image dimensions, creating function for, Insert Record server behavior 446-447 checking form input with, 316 Image Placeholder dialog box, displaying, 278 executing, 410 images using, 167-168, 184,371,374 adding to pages, 124 using with users.php page, 408 inserting paths to, 432 INSERT statement, example, 54 managing on servers, 400 Insert toolbar in Dreamweaver MX 2004, removing borders from, 131-l32 changesin,64-65 @import method, using with attached insertbar type, example of, 291 stylesheets, 145-146, 149 include files contents of, 268 avoiding problems with, 243-244 significance of, 267 pros and cons of, 246 INT data type styling, 240 example of, 52 using .php extension with, 244 explanation of, 49 integer variables, overview of, 8-9

517 Index

interface changes in Dreamweaver MX less than or equal to operator «=), 2004, overview of, 61-64 description of, 20 is_arrayO function, example of, 337 library items. See also code libraries isDOMRequiredO function, adding to applying styles and behaviors to, 225 PHPTime.js file, 272 converting code seetions into, 222-223 features of, 221 J handling with associated behaviors, JavaScript 225-226 adding for PHPTime.js file, 272-274 naming, 223 adding to onClick event, 271 options for, 224 creating external files for, 226 pros and cons of, 245 moving to external file, l33-l34 recommended contents of, 225 JavaScriptAPI, creating extensions with, 257 versus templates, 221 JavaScript techniques, overview of, 147 working with, 223-225 LIKE keyword, example of, 57 K line breaks, setting, l3 line numbers, turning on to avoid syntax Key column in MySQL tables, description errors, 304-309 of,33 lines and errors, relationship between, 301 keywords, list of reserved keywords, 229 links KILL command, advisory about, 351 advisory about updating of, 220 creating, 181 L previewing, 179 layers in Dreamweaver links within sites, managing with absolute positioning of, 420 Dreamweaver MX 2004, 80-81 explanation of, l35 listarticles.php page layout tables description of, 354 adding with Dreamweaver, 114-115 overview of, 402 setting up, 119 listmembers.php page layouts creating, 381-382 creating in Dreamweaver, 118-127 description of, 354 using CSS for, l34-145 lists LEFT JOIN, example of, 429, 443-444 marking as lists in XHTML, 92-94 Length/Values column in MySQL, styling, 140 description of, 50 Live Data view in Dreamweaver Lerdorf, Rasmus and development ofPHp, effect of, 242 1-2 features of, 163, 165 less than operator «) Liyanage, Mare and PHP package for Mac converting with htmlspecialcharsO OS X, 495 function, 318 locked areas, creating editable attributes description of, 20 in,214-216 Log In User server behavior, amending, 416

518 Index

Log Out User server behavior, settings for, 414 Macromedia Fireworks MX 2004 logic errors integration with Dreamweaver, chan ging array values, 329-331 significance of, 66-68 confusing assignment and equality magic_quotes_gpc option, significance operators, 327-328 of,316 endless loops, 328-329 mail() function, example of, 452-453 function arguments in wrong order, main.css file, contents of, 420 332-333 margins, setting in Dreamweaver, 116, 137 functions with no return value, 331-332 markup. See also HTML (Hypertext Markup overview of, 326-327 Language); XHTML (Extensible Hypertext Markup Language) useless loops, 329 adding with Property inspector, 108 logical And operator (&&) , description of, 20 best practices for, 91-95 logical Not operator (!), description of, 20 Master Detail Page Set feature, overview of, logical operators, overview of, 20 436-437 logicalOr operator CIIl media descriptors, support for, 147-149 description of, 20 member profiles, entering, 370 example of, 23 member records, editing, 384-390 login page, setting up for admin folder, memberdets.php page 411-413 main body of, 445-446 LONGBLOB field type, explanation of, 49 SQL query for, 443 LONGTEXT field type, explanation of, 49 members loops adding to administration section, 365-381 for loops, 24-25 creating list of, 381-384 troubleshooting, 328-329 members' details while loops, 25 displaying, 442 Lorem and More extension, downloading, 417 editing, 381-392 lowercase letters underlying dynamic structure of, 443 using with databases, 41 members' list, building, 434-436 using with SQL commands, 54 members table in Roundtree Garden Club case study M building structure for, 347-350 MacOSX contents of, 344-345 installing MySQL on, 497-499 membership category installing PHP on, 492-497 controlling, 356-365 locating PHP sites on, 492 settings for, 360 startingApache web server on, 487-491 menu.html file, creating for use with Macromedia Devnet, web address for, 144 includeO method, 237 Macromedia Exchange menu.php page result of searching for extensions with, 251 creating, 240-241 web address for, 249 description of, 354 and User Authentication server behavior, 416

519 Index

menus mysql-uroot -p command, explanation of, creating for Roundtree Garden Club 325-326 case study, 367 mysqLerrorO function, description of, 333 using extensions with, 259 messages for users, creating, 182-183 N Microsoft Excel, integration with \n escapable character, description of, 12 Dreamweaver MX 2004, 67-68 name, adding to acknowledgment page, Microsoft Word, integration with 457-458 Dreamweaver MX 2004, 67 natcasesortO function, effect of, 401 modulus operator (%), description of, 17 navigation areas, creating with Move To First Page server behavior, Dreamweaver, 122-127 adding, 200 navigation, creatingwith CSS, 137-142 MTAs (Mail Transport Agents), examples navigation list items, setting text properties of,453 for,142 multiplication operator (*), description of, 17   entries, controlling insertion of, 96 MX! file, creating to package extensions, nested if statements, example of, 452 290-293 Netscape 4, issues associated with, 145-146 My CD Collection page, naming, 162 network failure, troubleshooting, 326 MySQL New CSS Style dialog box assigning password for root user in, 485 creating selectors in, 140 common date format specifiers in, 428 displaying in Dreamweaver, 105, l32 configuring, 485 redefining style ofheading tags in, 122 creating new connection in, 359 New Document dialog box in downloading, 483 Dreamweaver MX 2004 installing, 484 changesin,62-63 installing on Mac OS X, 497-499 displaying, 117 resource for, 429 opening, 205-206,211 shutting down from New from Template dialog box, opening, 211 WinMySQLAdmin, 485 New Server Behavior dialog box, starting, 484-485 displaying, 280 MySQL databases $nomessage, testing, 455 examining structure oftables in, 33 noneditable areas. See also editable regions preparing dates for, 372-376 editing in parent templates, 2l3-214 MySQL Monitor tool identifying, 212 creating databases with, 41 nonemptyelements, relations hip to default databases in, 31 XHTML, 88-89 executing commands with, 32-34 normalization, relationship to databases, exiting, 487 47,344 field types in, 48-53 normalizing databases, 153-154 opening, 28-30 not equal operator (!=), description of, 20 selecting databases with, 30-32 not identical operator (!==), description of, 20 MySQL server, testing, 486-487 notices, suppressing in PHp, 314

520 Index

NOWO function, effect of, 54 logical operators, 20 Null column in MySQL, description of, 33, 51 overview of, 16-17 null data type, overview of, 16 string operators, 18-19 number variables, overview of, 8-9 ORDER BY button, sorting with, 197 numeric field types, overview of, 49 ordered lists NYPL Style Guide, web address for, 144 converting elements to, 108 guidelines for use of, 92-93 o objects p versus arrays, 16

tag, advisory about, 88-89 resource for, 306 page content, adding in Dreamweaver, 122 objectTagO function, using with page designs, displaying in Preview panel PHPTime.js file, 273 of Dreamweaver, 111 octa! notation, using with integer variables, 9 "Page Not Found" error, occurrence of, 321 onClick event, adding JavaScript to, 271 Page Properties dialog box in online resources Dreamweaver, features of, 109 CSS information, 144-145 page properties, setting with Dreamweaver, CSS Panic Guide, 145 116-118 CSS Zen Garden, 145 pages. See PHP pages; web pages CSS-Discuss, 144 parameters Macromedia Devnet, 144 adding for server behaviors, 283, 286 NYPL Style Guide, 144 adding to web pages, 172-173 phpMyAdmin, 34 parentheses (()), importance to includeO and requireO methods, 237 Real World Style, 145 parse error, example of, 302-303 Style Master, 113 parser token names, resource for, 302 themes,97 passwords. See also database password TopStyle CSS editor, 112 problems validator at W3C, 128, l30 assigning for root user in MySQL, 485 W3Schools, 144 encrypting, 409, 412 Web Standards Project, 144 ente ring in phpMyAdmin, 43 XHTML (Extensible Hypertext Markup storing in databases, 353 Language), 144-145 permissions, setting, 320 Open option for library items, explanation of,224 PHP 4.1.0, upgrading from, 494 Open SourceSafe Database dialog box, dis­ PHP 3.0, main feature of, 2 playing in Dreamweaver MX 2004, 75 PHP 5, downloading and installing, operators 480-481 arithmetic operators, 17-18 PHP 5, features of, 2 assignment operators, 16-17 PHP Date and Time extension, example of, 255-256 combining, 19 PHP elements, using Syntax Coloring comparison operators, 19-20 with,306

521 Index

, controlling downloading, 475 output of error messages with, 3l3-314 expressing dates and times in, 50 .php extension, significance of, 3 finding extensions for, 249-252 PHP files, saving, 206 installing, 475-477 PHP function arguments, troubleshooting installing on Mac OS X, 492-497 wrong order of, 332-333 overview of, 3 PHP functions resource for, 231 advisory about storing in separate sending email with, 452-453 files, 447 as server-side scripting language, 2 building, 228-230 using templates with, 218-221 versus constructs, 236 variables in, 7-16 importing with include Cl methods, PHP sites, locating on Mac OS X, 492 237-243 and tags, significance of, 3-4, naming, 229 6-7 returning values for, 230 PHP /Fr, development of, 1-2 reusing code with, 228-231 php.ini file, changing in PHP 5, 480-481 storing, 230-231 phpMyAdmin streamlining, 231 adding new columns to tables in, 440-441 without return values, 331-332 configuring, 35-37 PHP icons, examples of, 442-443 creating databases with, 40-41 PHP includes. See include files creating users rights with, 42-46 PHP Insert bar, proper use of, 298 displaying SQL window in, 53 PHP notices, suppressing, 314 downloading and installing, 34-35 PHP online documentation ente ring fields in, 48 for date calculations, 235 navigating, 38-40 for formatting strings with sprintO, 234 opening Query window in, 56 PHP pages. See also web pages setting authentication in, 36 creating templates for, 205-208 settings for admin table in, 352 example of, 4-6 settings for articles table in, 351 including code from external files in, settings for category table in, 347 236-244 settings for committee table in, 346 naming conventions for, 3 settings for members table in, 348 styling with CSS, 420-423 and SQL, 41 viewing,5 starting tables in, 47-51 viewing source for, 5 PHPTime dialog box, displaying, 277, 288 PHP (Personal Horne Page) PHPtime form, completing, 27l capabilities of, 2-3 PHPTime.gif file, saving, 275 comments in, 7 PHPTime.js file, creating, 272 configuring, 477-483 PHPTime.php page configuring Apache server for, 479-480 creating and saving, 276 definition of, 1 using with server behaviors, 280-287 development of, 1-2

522 Index pico, starting, 495-496, 497 properties picture details, handling, 400-402 for hover state, 142 picture menu, building for editartide.php setting for table cells, 133 page, 405 setting page properties with pk (primary key), significance of, 52 Dreamweaver, 116-118 placeholder text, highlighting, 209 setting text properties for navigation playlist table, creating, 47 list items, 142 playlisc* fields, defining, 52 Property inspector port 80, significance of, 464 features of, 108-109 POST array properties induded in, 67 checking for, 374 setting cell height and width in, 120 exploiting unset status of, 385 using extensions with, 262 POST methods, using with associative arrays, 15-16 Q preferences Query tab in phpAdmin, description of, 39 setting for XHTML in Dreamweaver, Query window, opening in phpMyAdmin, 56 95-96 quotation marks (") setting in Dreamweaver, 102-104 converting with htmlspecialcharsO Preload images check box in Dreamweaver, function, 318 effect of, 122-123 escaping in user input, 317 presentation, separation document using with arrays, 409 structure from, 97 using with string variables, 10-12,307 Preview panel of Dreamweaver, displaying page designs in, 111 using with strings, 307 previewing PHP pages, 370 using with XHTML, 87-88 previewing web pages, 175 Primary column in MySQL, description of, 51 R primarykey \r escapable character, description of, 12 assigning, 154 radbut dass, applying, 357 identifying records with, 187 radio buttons, inserting dynamic value for, passing to web pages, 181 363,370 relationship to databases, 46 radio groups, selecting dynamic value for, print _rO function, using with arrays, 330 388 print media descriptor in CSS2, read/write problems, troubleshooting, explanation of, 148 319-321 privileges, adding in phpMyAdmin, 44 Real World Style, web address for, 145 Privileges page, displaying in records phpMyAdmin, 42 adding to databases, 166 processing script, building for contact deleting from Roundtree Garden Club page,450-454 case study, 362 projection media descriptor in CSS2, displaying, 199 explanation of, 148 displaying in recordsets, 181

523 Index

displaying within recordsets, 162 Repeat Region server behavior identifying after updating, 187 adding to web pages, 173-176 inserting from cd table, 184 using with Roundtree Garden Club case maintaining integrity of, 359 study, 361, 384 updating while browsing tables, 440 repeating regions, using in tables, 439 Recordset dialog box, Advanced view of, 192 report pages, setting up for paging, 201 Recordset Paging server behavior, using, reporting database information, 196-201 200-201 reports, using extensions with, 260-261 recordsets requireO methods, using with extern al adding, 164-165 files, 236 building for editarticle.php page, 403 reserved keywords, list of, 229 creating for list of members, 381-382 Resource limits, specifying in creating for members in Roundtree phpMyAdmin, 44 Garden Club case study, 366-367, resource variables, overview of, 16 384-385 Restrict Access To Page server behavior, creating for Roundtree Garden Club applying, 413-415 case study, 358-364 rights, creating for users, 42-46 filtering, 177-182 rollover images, creating with modifying, 169-170 Dreamweaver, 122-127 selecting columns for, 170 root passwords, recovering, 325 selecting columns in, 173 Roundtree Garden Club case study setting up CD recordset, 191 adding and editing articles in, 397-405 specifying for repeated regions, 175 adding new members to, 365-381 in users.php page, 406 attaching stylesheet for, 355 using separately, 437-438 building committee list for, 437-441 using to retrieve data, 159-164 building database structure for, Recreate option for library items, 346-353 explanation of, 224 building detail page for, 441-447 redirect URL, using, 457-458 building front page for, 423-427 REFERENCES privilege in phpAdmin, building members' list for, 434-436 description of, 46 controlling committee and membership regions, repeating in web pages, 173-176 categories in, 356-364 register_globalsO function, default setting creating basic page framework for, for,415 418-419 regular expressions, purpose of, 451 creating contact page for, 448-456 relational databases, advisory about, 358 creating database for, 345-346 remote servers creating personalized acknowledgment configuring with Dreamweaver MX for,457-458 2004, 75 CSS styles for main pages ofweb site uploading files to, 365 for, 421-423 Reopen documents option in displaying full articles in, 427-434 Dreamweaver MX 2004, significance editing members' details in, 381-392 of,68-69 front end of, 418

524 Index

handling problems with User s Authentication server behaviors, Save As Template dialog box, opening, 415-417 206-207 overview of, 341-343 save desktop option in Dreamweaver MX overview of administration files, 354 2004, significance of, 68-69 planning database for, 344-345 screen media descriptor in CSS2, securing admin folder in, 405-415 explanation of, 148 setting up site for, 353 script flow, controlling, 308 styling pages with CSS, 420-423 Search tab in phpAdmin, description of, 39 tables in, 344 Select Extension to Install dialog box, rows displaying, 253 explanation of, 46 SELECT statement, example of, 56-57 inserting in databases, 55 selectors, creating in New CSS Style dialog selecting, 57 box, 140 rstArticie recordset semicolon (;) creating, 430 including, 299 SQL query for, 428 significance of, 4, 12,308 rstArtists recordset, creating, 164 in SQL, 55-56 rstArtSumm recordset, creating, 424 usingwith MySQL commands, 32, 41 rstAuthors recordset Server Behavior Builder dialog box creating, 399 expanding, 285 usingwith editarticle.php page, 403 modifying, 287-288 rstCDS recordset, creating, 160-161, 180, 191 server behaviors rstGetArticie recordset, using with adding, 182 editarticle.php page, 403 creating, 377-380 rstGetDets recordset, creating, 384 Delete Record, 188-190, 196 rstMembers recordset, creating, 434 Insert Record, 167-168, 184,316 rstMemList recordset, creating, 381 properremovalof,297 rstUname recordset, purpose of, 408 Recordset Paging, 200-201 runtime errors Repeat Region, 173-176 calls to undefined functions, 318-319 selecting defaults for, 378 database connection problems, Show Region, 188-190 321-325 Update Record, 187, 195,316 database password problems, 325-326 using, 162-164 "headers already sent", 319 using extensions with, 264, 280-287 network failure, 326 using Insert Record server behavior, overview of, 311 167-168 problems with user input, 312-318 server formats, using extensions with, 265 read/write problems, 319-321 server models, using extensions with, 266 server technology, selecting for Dreamweaver MX 2004 sites, 72

525 Index

session variables, passing names as, 458 Snippets panel sessionJegisterO function, problem versus extensions, 247 associated with, 415 features of, 227 session_startO function, using with User pros and cons of, 246 Authentication server behaviors, 414 saving code in, 231-235 sessions, configuring in PHp, 478 versus templates and library items, seCerrochandlerO built-in function, 226-227 description of, 323 sorting CD tides, 197 shorthand syntax, example of, 103 source, viewing for PHP pages, 5 show databases command, issuing in special characters. See also characters MySQL Monitor, 31, 486 resource for, 317 Show Region server behavior, using, using correct character entities for, 188-190 94-95 showValO function Splitview debugging with, 335-339 displaying library items in, 223 displaying contents of SQL queries working in, 297 with,336 sprintfO function improving, 337-338 versus printfO function, 334 and superglobal arrays, 338-339 resource for, 334 using with variables, 337 using with snippets, 234 single quotes Cl SQL commands, using uppercase for, 54 converting with htmlspecialcharsO function, 318 SQL queries using with string variables, 10,307 constructing for detail page, 443-444 Site menu, checking files in and out from, 78 displaying content of, 335 site reports, using extensions with, 260-261 including variables in, 404 sites. See web sites locating, 334-335 Size drop-down menu in Dreamweaver, for rstArticle, 428 advisoryabout, 109 SQL (Structured Query Language) slash-asterisk (/*), significance of, 7 adding columns to, 193 slashes (/ /), significance of, 7 for admin table, 353 SMALLINT data type, explanation of, 49 for articles table, 351 smart form validation, code for, 450-451 creating recordsets with, 160-161 dialog box, displaying, 232 creating tables with, 156 snippet folders, naming, 231-232 deleting data with, 58-59 Snippet type, Wrap default for, 233 inserting data with, 54-56 snippets for members table, 348-349 editing and deleting, 234 relationship to phpMyAdmin, 41 naming, 232-233 selecting data with, 56-57 obtaining online, 235 updating data with, 57-58 storing dateO formats as, 234-235 SQL tab in phpAdmin, description of, 39 Snippets Exchange, web address for, 235

526 Index

SQL window, displaying gin stylesheets phpMyAdmin, 53 attaching for administration section, 355 start page in Dreamweaver MX 2004, attaching in Netscape 4, 145 changesin,61-62 attaching with CSS Styles panel, stateless environment, explanation of, 415 107-108 static outline, creating for committee and creating with CSS Styles panel, 104-106 membership categories, 356-358 displaying at design time, 112 static sites, guidelines for creation of, in Dreamweaver, 109-110 417-418 using prebuilt CSS in Dreamweaver, Sticky edit field server behavior, creating, 109-110 377-381,385,399 using with media descriptors, 148-149 str_replaceO function, finding commas subtraction operator (-), description of, 17 with,315 superglobal arrays, using, 338-339 Strict XHTML Suraski, Zeev and development of PHP 3.0, characteristics of, 85 1-2 moving to, 128-l33 switch statements, overview of, 23-24 string operators, overview of, 18-19 syntactical devices, controlling script flow string variables with,308 double quotes (") used with, 10-12 syntax coloring, avoiding syntax errors explanation of, 9 with, 305-307 heredoc syntax used with, 12-13 syntax errors single quotes C) used with, 10 avoiding, 304-311 strings, using quotes with, 307 handling error messages, 299-303 strip_tagsO function, effect of, 452 incorrectly embedded elements, stripslashesO function, example of, 317 297-298 and versus and d>, versus logic errors, 328 significance of, 95 missing semicolons, 299 tags, wrapping overview of, 296-297, 298 elements in, 108 tracking down, 301 strposO function, purpose of, 375 strtotimeO format, result of, 235 T structural markup, adding with Property inspector, 108 \ t escapable character, description of, 12 Structure privileges in phpAdmin, T_STRING parser token, significance of, 302 description of, 46 Tab key, advisory about indenting with, 309 Structure tab in phpAdmin, description of, 39 table cells, setting properties of, 133 structure, using heading tags for, 91-92 Table dialog box, displaying in Style drop-down menu in Dreamweaver, Dreamweaver, 115 features of, 109 table structure, examining in MySQL Style Master, web address for, 113 databases, 33 styles, applying to library items, 225

527 Index

tables detaching child pages from, 218 adding and listing dynamic data in, guidelines for use of, 134, 203-205 170-174 versus library items, 221 adding columns to, 439-441 propagating changes from, 213-214 adding for CD information, 180 pros and cons of, 245 adding to forms, 268 using with PHp, 218-221 creating, 156 test.php page, creating, 301 creating in forms, 365 TEXT field type, explanation of, 49 defining fields for, 51-53 text field types, overview of, 48-49 including repeating regions in, 439 text, linking to web pages, 186 inserting for CD report, 198 text properties, setting for navigation list joining, 193 items, 142 overview of, 46-47 thanks.php page, personalizing, 457-458 in Roundtree Garden Club case study, themes, site for, 97 344-345 "There is an error in your SQL" error, starting in phpMyAdmin, 47-51 occurrence of, 351 tables for layout $this, result of using as variable, 306 adding with Dreamweaver, 114-115 thispage id, controlling down state of setting up, 119 buttons with, 214 tag attributes, making editable, 215 time tag editor, opening tag for, 270 displaying in upper- or lowercase in tag libraries and tag editors, using server behaviors, 284 extensions with, 261-262 formatting, 267 tag styles, configuring in PHp, 477 TIM ES TAMP field, explanation of, 50 tags TIMESTAMPO function, effect of, 54 redefining appearance in browsers, timestamps 100-101 updating in playlist table, 57-58 spaces used with, 89 using with date calculations, 235 using with PHp, 3, 7 toolbars, using extensions with, 259-260 tcsh shell, setting path for, 499 TopStyle CSS editor, integration with template objects, benefits of, 221 Dreamweaver, 112-113 Template Properties dialog box, editing (table row), selecting, 175 attributes in, 217 Transitional DTD documents, converting template tags, surrounding

tags to Strict DTD, 129 with,210 Transitional XHTML, characteristics of, templates 85-86 adding editable areas to, 208-211 trigger_errorO function, explanation of, advisory about saving of, 208 323,325 creating child pages from, 211-213 trimO function, effect of, 452 creating for PHP pages, 205-208 tty media descriptor in CSS2, explanation of,148

528 Index tv media descriptor in CSS2, explanation User Authentication server behavior of,148 applying to pages, 4l3-415 .txt extension, advisory about, 493 creating, 411-412 Type column in MySQL, description of, 33, handling problems with, 415-417 48-50 user input types, downloading information about, 291 dealing with unwanted or unexpected characters in, 316-318 u escaping apostrophes and quotes in, 317 umaskO function, overriding fopenO runtime errors associated with, setting of 666 with, 320 312-318 underscore U, using with variables, 8 validating, 312-3l3 undoing actions, 297 users with rights, creating, 42-46 Unicode character entities, using for users.php page special characters, 94-95 creating, 405 Unique column in MySQL, description of, 51 description of, 354 UNIX_TIMESTAMPO function, explanation settings for recordsets in, 406 of,50 useUpper parameter, creating, 284 unordered lists utility API, creating extensions with, 256 converting elements to, 108 guidelines for use of, 93 v unsigned field valid types, downloading information example of, 52 about, 291 explanation of, 49 Validate Form function upcase checkbox, adding, 269 applying to Roundtree Garden Club Update Record server behavior case study, 371 checking form input with, 316 using, 168-169,312-313 locating, 390 validation, adding to web pages, 168-169 settings for, 390 validator errors and solutions, list of, l31 using, 187, 195 Validator page, options on, 96 UPDATE statement, example of, 57-58 validator, running in Dreamweaver, UPPER function, example of, 399 127-129,371 uppercase letters, using with SQL values commands, 54 assigning to arrays, 14-15 URLs (uniform resource locators) returning for PHP functions, 230 ente ring and testing in Dreamweaver testing for, 315-316 MX 2004, 74 VARCHAR data type linking to, 177, 182 example of, 52 redirecting, 457-458 explanation of, 48-49 use mysql command, issuing in MySQL variable expansion, explanation of, 10-11 Monitor, 31 variable scope, significance of, 332

529 Index

variable types creating front end of, 417 arrays, 14-16 creating for use with Dreamweaver MX Booleans, 13 2004, 71-77 nulls, 16 date functions in MySQL, 428 numbers, 8-9 DreamweaverMX2004 7.0.1 updater, 500 objects, 16 Dreamweaver MX 2004 trial version, 501 resources, 16 email headers and uses, 453 strings, 9-13 Macromedia Exchange, 249 variables Macromedia Extension Manager, including in SQL queries, 404 247-249 naming,8 Macromedia valid types, 291 overview of, 7-8 main pages of Roundtree Garden Club case study, 421-423 for SQL queries, 334 managing with Dreamweaver MX 2004, testing for arrays in, 337 77-81 $this as, 306 MySQL,483 using $ (dollar) sign with, 299 MySQL download, 497 virtual hosts, creating for Apache on objects and classes, 306 Windows systems, 472-475 parser token names, 302 votes, updating in playlist table, 57-58 PHP (Personal Horne Page), 475 Regular Expression Library, 451 w replacing links in, 80-81 W3C validator root -password recovery, 325 accessing, 128, 130 Snippets Exchange, 235 using with dynamic pages, 150 special characters, 317 W3Schools, web address for, 144 sprintO function, 334 web pages. See also PHP pages strposO function, 375 adding parameters to, 172-173 uploading files to remote servers, 365 adding validation to, 168-169 validator at W3C, 128 advisory about testing of, 168 Web Standards Project, web address for, connecting to databases, 157-159 144 linking text to, 186 "Welcome to PHP1," writing to web previewing, 175 browser, 4, 6 repeating regions in, 173-176 well formed XHTML, explanation of, 89 selectively displaying areas of, 182-185 WHERE clauses web sites guidelines for use of, 395 access contro!, 355 using with editarticle.php page, 403 Apache web server for Windows while loops, overview of, 25 systems, 462 white space, making code more readable array sorting, 401 with, 308-309 array_walkO function, 339 Check Form MX validator, 371

530 Index

Windows systems closing tags for nonempty elements in, configuring Apache web server on, 88-89 468-475 displaying, 333 creating Apache aliases on, 472 drawback to including menus as, 240 downloading Apache web server for, and DTDs, 85-87 461-462 empty elements in, 89 installing Apache web server on, example of, 125-127 462-466 justifications for use of, 83-85 setting up default environment for marking lists as lists in, 92-94 Apache web server on, 471-475 nesting in, 89-90 setting up global environment for online resources for, 144-145 Apache web server on, 469-470 quotation marks in, 87-88 starting and testing Apache web server on,466-468 for Roundtree Garden Club case study, 419 Windows systems, opening Extension mies for writing of, 85-90 ~anageron,247-248 setting Dreamweaver preferences for, Word, integration with Dreamweaver MX 95-96 2004,67 using heading tags with, 91-92 wordwrap XHT~L Frameset, characteristics of, 86 avoiding syntax errors with, 305 XHT~L functions, importing with using with Code view, 368 includeO methods, 237-243 workspace in Dreamweaver MX 2004, XHT~L Strict, moving to, 128-133 examining, 62-64 XHT~L Transitional, characteristics of, 85 Wrap default for Snippet type, significance «?xml version="l.O" encoding= "UTF-8" of,233 ?> 1~L declaration, meaning of, 87 xor operator x description of, 20 example of, 401-402 XHT~L doctypes, advisory about, 369 XHT~L documents y creating in Dreamweaver, 113 validating, 127-128 YYYY-~~-DD format, meaning of, 49

XHT~L (Extensible Hypertext ~arkup Languagel. See also HT~L (Hypertext z ~arkup Languagel; markup Zend Engine, development of, 2 attribute minimization in, 90 zerodiv.php page, creating, 312 case-sensitivity of, 88

531 forums apress com FOR PROFESSIONALS BY PROFESSIONALS

JOIN THE APRESS FORUMS AND BE PART OF OUR COMMUNI1Y You'll find discussions that cover topics of irlterest to IT professionals, programmers, and erlUlusiasts Just like you, If you post a query to arie of our forums, you can expect that some of the best minds in the business-especially Apress authors, who all write with The Expert's Voice ™ -will chime in to help you. Why not aim to become one of our most valuable partic­ ipants (MVPs) arid wirl cool stuff? Here's a samplirlg of wllat you'll firld:

DATABASES PROGRAMMING/BUSINESS Data drives everylhing, Unlortunately, it is, Share information, exchange ideas, and discuss any database Talk about the Apress line of books that cover software programming or aelministration issues, methoelology, IJest practices, anelll0w programmers interact willl the "suits."

INTERNET TECHNOLOGIES AND NETWORKING WEB DEVELOPMENT/DESIGN Try living without plumbing (and eventually IPv6), Ugly doesn't cut it anymore, and CGI is absurd, Talk alJout nelworking topics inclueling protocols, design, Help is in sigllt for your site, Finel design solutions for your administration, wireless, wired, storage, backup, certifications projects and get ideas for building an interactive Web site trends, and new technologies,

JAVA SECURITY We've come a long way lrom the old Oak tree. Lots 01 bad guys out there-the good guys need help. Hang out and eliscuss Java in whatever flavor you cll00se Discuss computer and network securily issues here, Just don't let J2SE, J2EE, J2ME. Jakarta, and so on anyone else know the answers l

MAC OSX TECHNOLOGY IN ACTION All about the Zen 01 OS X, Cool things, Fun things, OS X is both the present and the future for Mac apps. Make It's after hours. It's time to play. Whether you're into LEGOoO suggestions, offer up ideas, or IJoast about your new hardware, MINDSTORMSTM or turning an old pe into a DVR, this is wllere technology turns into fun

OPEN SOURCE WINDOWS Source code is good; understanding (open) source is betteL No delenestration here, Discuss open source teclmologies an el related topics SUCll as Ask questions alJout all aspects of Winelows programming, get PHP, MySOL, Linux, , Apache, Python and more help on Microsoft technologies covered in Apress books, or proviele feedlJack on any Apress Winelows book,

HOW TO PARTICIPATE: Go to the Apress Forums site at http://forums.apress.com/, Click the New User link.