. 93
( 132 .)


PHP Function Reference
Regular Expressions Overview
Helpful User-Defined Functions
PHP and MySQL Resources
MySQL Function Reference
Appendix A

What™s on the CD-ROM
THIS with information on the contents of the CD that
accompanies this book. For the latest and greatest information, please refer to the
ReadMe file located at the root of the CD. Here is what you will find:

— System Requirements

— Using the CD

— What™s on the CD

— Troubleshooting

System Requirements
Make sure that your computer meets the minimum system requirements listed in
this section. If your computer doesn™t match up to most of these requirements, you
may have a problem using the contents of the CD.
For Windows 9x, Windows 2000, Windows NT4 (with SP 4 or later), Windows
Me, or Windows XP:

— PC with a Pentium processor running at 120 MHz or faster

— At least 32MB of total RAM installed on your computer; for best perfor-
mance, we recommend at least 64MB

For Linux/Unix:

— PC with a Pentium processor running at 90 MHz or faster

— At least 32MB of total RAM installed on your computer; for best perfor-
mance, we recommend at least 64MB

For Macintosh:

— Mac OS computer running OS X or later

— At least 32MB of total RAM installed on your computer; for best perfor-
mance, we recommend at least 64MB
558 Part V: Appendixes

Using the CD
The contents of this CD are set up as a folder structure. To access the files you want
to work with, access the appropriate folder (apache, mysql, php, and so on). Note:
To access the example applications from the book open the book folder and explore
its contents.

What™s on the CD
The following sections provide a summary of the software and other materials you™ll
find on the CD.

Example applications
To get the applications in Sections III and IV working you first need to install
Apache, PHP, and MySQL. You can find these applications on this book™s CD-ROM.
You can follow the instructions in Appendix C to install these applications.
Once Apache, PHP, and MySQL are installed, you need to copy the PHP scripts
that load the databases and run the applications. Copy the entire /book directory
from the CD, with all of its subfolders, to somewhere under the htdocs/ directory of
your Apache installation, so that you can browse to http://myserver/book/ (or
http://myserver/monkeying/with/php5/book/, and so on)
Check the README.TXT file in this directory for further instructions. Primarily,
you will need to edit the book.ini file and set the values defined there to match your
local configuration.

On the CD, in addition to the code for the examples detailed in this book (as well as
some extra ones), you™ll find the following:

— MySQL ” Files for installing a recent version of MySQL 4.0. For more
information, and a more recent version, check their Web site at http://

— Apache ” Files for installing a recent version of the Apache Web server
(go to http://www.apache.org for more information).
— PHP ” Files for installing PHP 4 on your machine. Be sure to install
Apache and MySQL first.
Appendix A: What™s on the CD-ROM 559

— PHP 5 beta ” Files for installing the beta version of PHP 5 that was avail-
able at the time of publication. If you have access to the Web, check the
PHP site at http://www.php.net for more recent developments. You
can also find absolutely up-to-the-minute development versions at

— Adobe Acrobat Reader ” Tool for reading files in the Portable Document
Format (PDF).
— Scripts from Appendix H.

All files with .php extensions can simply be copied to the Web server directory
and will execute when the page is accessed.
Files with .tar.gz extensions are intended for Unix systems and must be uncom-
pressed before you will be able to use them. Use the following commands:

gunzip filename.tar.gz
tar xf filename.tar

All files with .zip extensions must be uncompressed using a Windows zip utility
such as WinZip (available at http://www.winzip.com).
Once you™ve uncompressed the packages, see the README or INSTALL files for
installation instructions.

For more information on installing and configuring MySQL, PHP, and
Apache, see Appendix C.

Shareware programs are fully functional, trial versions of copyrighted programs.
If you like particular programs, register with their authors for a nominal fee and
receive licenses, enhanced versions, and technical support. Freeware programs are
copyrighted games, applications, and utilities that are free for personal use. Unlike
shareware, these programs do not require a fee or provide technical support. GNU
software is governed by its own license, which is included inside the folder of the
GNU product. See the GNU license for more details.
Trial, demo, or evaluation versions are usually limited either by time or func-
tionality (such as being unable to save projects). Some trial versions are very sensi-
tive to system date changes. If you alter your computer™s date, the programs will
“time out” and will no longer be functional.
560 Part V: Appendixes

eBook version of MySQL/PHP Database
Applications, Second Edition
The complete text of this book is on the CD in Adobe™s Portable Document Format
(PDF). You can read and search through the file with the Adobe Acrobat Reader
(also included on the CD).

If you have difficulty installing or using any of the materials on the companion CD,
try the following solutions:

— Turn off any antivirus software that you may have running ” Installers
sometimes mimic virus activity and can make your computer incorrectly
believe that it is being infected by a virus. (Be sure to turn the antivirus
software back on later.)
— Close all running programs ” The more programs you™re running, the less
memory is available to other programs. Installers also typically update
files and programs; if you keep other programs running, installation may
not work properly.
— Reference the ReadMe ” Please refer to the ReadMe file located at the root
of the CD-ROM for the latest product information at the time of publication.

If you still have trouble with the CD-ROM, please call the Wiley Product
Technical Support phone number: (800) 762-2974. Outside the United States, call
1(317) 572-3994. You can also contact Wiley Product Technical Support at
www.wiley.com/techsupport. Wiley Publishing will provide technical support
only for installation and other general quality control items; for technical support
on the applications themselves, consult the program™s vendor or author.
To place additional orders or to request information about other Wiley products,
please call (800) 225-5945.
Appendix B

HTML Forms
IF YOU WANT YOUR APPLICATIONS to take user data, you are going to need to provide
a place for users to enter the data. That requires HTML forms (or, if you want to be
fancy, PDF files or Macromedia Flash applications, but those are subjects unto
themselves). HTML forms are easy enough to work with. Several commonly used
input types are available, and in browsers that make use of HTML 4.0 and
Cascading Style Sheets you can use certain techniques to make your forms a bit
fancier. A full discussion of everything you can do with forms is beyond the scope
of this book. If you need more information on forms and how they can work with
CSS or JavaScript, or on some of the newer browser-specific form types, check out
the documentation at http://microsoft.com or http://mozilla.org. There is
also a great resource for questions about how different tags and attributes work in
different browsers at the Index DOT Html site, http://www.blooberry.com/
indexdot/html/. You™ll find the official documentation at http://www.w3c.org/

Form Basics
Each form is delimited by opening and closing <form> tags. The <form> tag takes
the following attributes:

— action ” This attribute specifies the URL of the page that a form will be
sent to for processing. It can contain a relative URL (such as myscript.
php or ../myfolder/myscript) or a complete URL (such as http://

— method ” This attribute indicates the HTTP request type the browser will
send to the server. It must be set to either GET or POST. If you set it to GET,
the name/value pairs will appear in the browser™s location bar (as in
http://mypage.com?name1=value1&name2=value2). The advantage
of using GET is that results can be bookmarked in the browser and that
debugging is easier. The disadvantage is that the variables you send will
be more transparent. If you set the method attribute to POST the name/
value pairs will not be visible. The default value of this attribute is GET.
— name ” This attribute is most useful for addressing portions of a form
through JavaScript, though it can also be used for CGI applications.
The form name is not sent to the server when the form is submitted.
562 Part V: Appendixes

— enctype ” This attribute has a default value of application-x-www-
form-urlencoded, and this is normally be fine. But if you are uploading
files (using <input type=”file”>) you should use multipart/form-data.

A typical form shell will look something like this:

<form name=”myform” action=”processor.php” method=”POST”>

Input Types
Most of the work in your forms will be done by the input types. An input tag and
the type attribute determine what kind of form element is rendered in your browser.
Every form field must have a name attribute. The name you give the form field is
used by PHP to identify the value that was placed in it. See the code sample that
follows shortly for a concrete example. (To be absolutely accurate, you don™t need
to supply name attributes to submit and reset buttons, but doing so makes it easier
to retrieve values from form elements. Otherwise, you™re stuck doing it via array
As a quick example, the following would create a simple form with a single text
box and a submit button. The text box has the default value of “hello there”, as
shown in Figure B-1.

<input type=”text” size=”50” maxlength=”15”
value=”hello there”><br>
<input type=”submit” name=”submit” value=”OK?”>

The input types are as follows. Note that different input types have different
attributes associated with them. Each of them takes a name attribute.

— text ” This type is shown in the preceding example. It can take these
size ” Indicates the length of the box rendered in the Web browser.

maxlength ” Limits the number of characters that can be inputted into

the field. Keep in mind that older browsers will ignore maxlength;
even in newer browsers you should not rely on this attribute to limit
value ” The default value in the box. The user can override it by

typing in different information.
Appendix B: HTML Forms 563

Figure B-1: A simple HTML form


. 93
( 132 .)