Table Of Contentspine=1.68"
Wrox Programmer to ProgrammerTM Wrox Programmer to ProgrammerTM
Beginning
Boronczyk,
PHP6, Apache, MySQL® Naramore, Gerner,
Le Scouarnec,
Web Development
Stolz, Glass
With this guide, you’ll quickly learn why the combination of PHP, Apache, and Beginning
MySQL is rapidly becoming the most popular way to develop dynamic web
sites. It gives you the best possible foundation for understanding how the core
WP
components work separately and together, enabling you to take full advantage
of everything they have to offer.
eH
You’ll discover how to utilize the key features of these technologies as you follow
two projects to create complete web sites. These projects take you through b
the basics, such as writing PHP code, building a MySQL database, filling the P
database with data, and showing specific information to your visitors. You’ll then
D
incorporate some of the more complex topics of working with PHP, Apache, and 6
MySQL as you progress step by step through the development of each site. e Beginning
When you’ve finished this book, you’ll have a thorough understanding of the ,
v
core concepts you need to become an effective developer. Plus you’ll be able to
create a well-designed, dynamic web site using freely available tools. eA
What you will learn from this book l PHP6, Apache,
o
● Installation and configuration of PHP, Apache, and MySQL p
● Ways to avoid errors and how to handle them when they occur p
a
● Techniques for creating, altering, and working with image files
m
● Steps for building a content management system
c
● How to monitor your web site through activity logs and error logs
e
● Setting up e-mail lists and handling user registrations h MySQL
● Tips for adding e-commerce capabilities n ®
● How to connect to MySQL from PHP te
Who this book is for Enhance Your Knowledge
Advance Your Career ,
This book is for PHP beginners who have some experience with web site
development concepts and a basic working knowledge of HTML and CSS.
M
Web Development
Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing
y
a structured, tutorial format that will guide you through all the techniques involved.
S
Q
www.wrox.com
L
Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec,
Recommended PHP, Database Management ISBN: 978-0-470-39114-3
Computer Book ® Jeremy Stolz, Michael K. Glass
Categories Web Page Design
$49.99 USA
$59.99 CAN Updates, source code, and Wrox technical support at www.wrox.com
spine=tk"
Beginning
PHP6, Apache, MySQL®
™
Programmer to Programmer
Web Development
Get more out of
Professional Web APIs with PHP
978-0-7645-8954-6
WROX.com This book is for programmers who have a strong understanding of
PHP and are looking for detailed coverage of multiple APIs in PHP.
Professional Joomla!
978-0-470-13394-1
This book is for web developers, hobbyists, web designers, blog-
gers, corporate content creators, and support specialists who are
looking to build a more robust web site. Basic skills in the area of
PHP programming are necessary.
PHP and MySQL Create-Modify-Reuse
Interact Chapters on Demand
978-0-470-19242-9
This book is for anyone who is familiar with the fundamentals of
Take an active role online by participating in Purchase individual book chapters in pdf programming in PHP and MySQL and is interested in program-
ming a variety of applications.
our P2P forums format
Beginning PHP6, Apache, MySQL
Web Development
Wrox Online Library Join the Community
978-0-470-39114-3
This book is for the PHP beginners who have some experience
Hundreds of our books are available online Sign up for our free monthly newsletter at
with web site development concepts and a basic working knowl-
through Books24x7.com newsletter.wrox.com edge of HTML and CSS.
Beginning CSS: Cascading Style Sheets
Wrox Blox Browse for Web Design, 2nd Edition
978-0-470-09697-0
This book discusses how to style XML documents with CSS—XML
Download short informational pieces and Ready for more Wrox? We have books and
being a more advanced markup language with multipurpose
code to keep you up to date and out of e-books available on .NET, SQL Server, Java, applications. XML will play an increasingly larger role in the
trouble! XML, Visual Basic, C#/ C++, and much more! Enhance Your Knowledge production of XHTML documents in the future.
Advance Your Career Beginning MySQL
978-0-7645-7950-9
This book is for programmers who are new to MySQL but who
have some experience in PHP, Java, or ASP/ASP.NET developing
applications that access backend databases.
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com
Beginning
®
PHP6, Apache, MySQL Web Development
Introduction .........................................................................................................xxiii
Part I: Movie Review Web Site
Chapter 1: Configuring Your Installation ..........................................................3
Chapter 2: Creating PHP Pages Using PHP6 ..................................................19
Chapter 3: Using PHP with MySQL ................................................................77
Chapter 4: Using Tables to Display Data ......................................................105
Chapter 5: Form Elements: Letting the User Work with Data ........................131
Chapter 6: Letting the User Edit the Database .............................................153
Chapter 7: Manipulating and Creating Images with PHP...............................175
Chapter 8: Validating User Input .................................................................217
Chapter 9: Handling and Avoiding Errors ......................................................241
Part II: Comic Book Fan Site
Chapter 10: Building Databases ..................................................................263
Chapter 11: Sending E-mail .........................................................................315
Chapter 12: User Logins, Profiles, and Personalization .................................355
Chapter 13: Building a Content Management System ..................................407
Chapter 14: Mailing Lists ............................................................................469
Chapter 15: Online Stores ...........................................................................505
Chapter 16: Creating a Bulletin Board System .............................................557
Chapter 17: Using Log Files to Improve Your Site .........................................627
Chapter 18: Troubleshooting .......................................................................641
Appendix A: Answers to Exercises ..............................................................649
Appendix B: PHP Quick Reference...............................................................685
(continued)
ffffiirrss..iinndddd ii 1122//1122//0088 1100::4488::1199 AAMM
Appendix C: PHP6 Functions .......................................................................695
Appendix D: MySQL Data Types ...................................................................753
Appendix E: MySQL Quick Reference ...........................................................757
Appendix F: Comparison of Text Editors .......................................................761
Appendix G: Choosing a Third-Party Host .....................................................765
Appendix H: An Introduction to PHP Data Objects ........................................769
Appendix I: Installation and Configuration on Linux ......................................777
Index .........................................................................................................785
ffffiirrss..iinndddd iiii 1122//1122//0088 1100::4488::2200 AAMM
Beginning
PHP6, Apache, MySQL® Web Development
ffffiirrss..iinndddd iiiiii 1122//1122//0088 1100::4488::2200 AAMM
ffffiirrss..iinndddd iivv 1122//1122//0088 1100::4488::2200 AAMM
Beginning
PHP6, Apache, MySQL® Web Development
Timothy Boronczyk
Elizabeth Naramore
Jason Gerner
Yann Le Scouarnec
Jeremy Stolz
Michael K. Glass
Wiley Publishing, Inc.
ffffiirrss..iinndddd vv 1122//1122//0088 1100::4488::2211 AAMM
®
Beginning PHP6, Apache, MySQL Web Development
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-39114-3
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data.
Beginning PHP6, Apache, MySQL web development / Timothy Boronczyk . . . [et al.].
p. cm.
Includes index.
ISBN 978-0-470-39114-3 (paper/website)
1. Web sites—Design. 2. Apache (Computer file : Apache Group) 3. PHP (Computer program
language) 4. MySQL (Electronic resource) I. Boronczyk, Tim, 1979-
TK5105.888.B426 2009
006.7'8—dc22
2008047012
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written
permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the
Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.
Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley &
Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or
warranties with respect to the accuracy or completeness of the contents of this work and specifically
disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No
warranty may be created or extended by sales or promotional materials. The advice and strategies contained
herein may not be suitable for every situation. This work is sold with the understanding that the publisher is
not engaged in rendering legal, accounting, or other professional services. If professional assistance is
required, the services of a competent professional person should be sought. Neither the publisher nor the
author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in
this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Web site may provide or recommendations it may
make. Further, readers should be aware that Internet Web sites listed in this work may have changed or
disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department
within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related
trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the
United States and other countries, and may not be used without written permission. MySQL is a registered
trademark of MySQL AB. All other trademarks are the property of their respective owners. Wiley
Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
ffffiirrss..iinndddd vvii 1122//1122//0088 1100::4488::2211 AAMM
About the Authors
Timothy Boronczyk is a native of Syracuse, New York, where he works as a programmer by day and a
freelance developer, writer, and technical editor by night. He has been involved in web design since
1998, and over the years has written several articles on PHP programming and various design topics, as
well as the book PHP and MySQL: Create - Modify - Reuse (Wrox). Timothy holds a degree in software
application programming, is a Zend Certified Engineer, and recently started his first business venture,
Salt City Tech ( www.saltcitytech.com ). In his spare time, he enjoys photography, hanging out with
friends, and sleeping with his feet hanging off the end of his bed. He ’ s easily distracted by shiny objects.
Elizabeth Naramore graduated from Miami University (Ohio) with a degree in organizational behavior
and has been a web developer since 1997. Her main focus is in e - commerce, but she develops sites across
numerous industries. She is currently a moderator at PHPBuilder.com, an online help center for PHP.
She lives in Cincinnati, Ohio, with her husband and two children, and looks forward to someday
returning to Miami U. to get her masters in computer science.
Jason “ Goldbug ” Gerner currently spends his days working as a web developer in Cincinnati and burns
free time complaining about lack of support for web standards and abusing XML. He can often be found
lurking in the PHPBuilder.com discussion forums, waiting to chime in with nagging comments about
CSS or code efficiency.
Yann “ Bunkermaster ” Le Scouarnec is the senior developer for Jolt Online Gaming, a British gaming
company. He is a moderator at PHPBuilder.com and a developer of open source PHP software for the
gaming community. He has also worked for major software corporations as a software quality expert.
Jeremy “ Stolzyboy ” Stolz is a web developer at J & M Companies, Inc. (w ww.jmcompanies.com ), a print
company in Fargo, North Dakota. Jeremy is primarily a PHP/MySQL developer, but he has also worked
with many other languages. When not working, he frequents the Internet and tries to keep his
programming skills sharp and up to date. He is a contributor to and moderator at PHPBuilder.com.
Michael “ BuzzLY ” Glass has been a gladiator in the software/Web site development arena for more
than eight years. He has more than ten years of commercial programming experience with a wide
variety of technologies, including PHP, Java, Lotus Domino, and Vignette StoryServer. He divides his
time between computer programming, playing pool in the APA, and running his web site at
www.ultimatespin.com . You can usually find him slinking around on the PHPBuilder.com forums,
where he is a moderator with the nickname BuzzLY.
ffffiirrss..iinndddd vviiii 1122//1122//0088 1100::4488::2222 AAMM
ffffiirrss..iinndddd vviiiiii 1122//1122//0088 1100::4488::2222 AAMM
Description:Offering a step-by-step walk through understanding the three key open source technologies that form the basis for most active web servers, this book demonstrates how to quickly create a professional-looking, functional site using Apache Web server, the MySQL database system, and the PHP scripting la