For Prof. Gegee!!!

profilejurekmg1980
php_programming_with_mysql_second_edition_good.pdf

<!— THE WEB TECHNOLOGIES SERIES

1 flum m ..

PHP 1m PROGRAMMINGM

km ml. WITH MySQL

// SECOND EDITION U '

V :DON GOSSELIN §

:DIANA KOKOSKA l :R0BERT EASTERBROOKS I

‘ÿIrfjif

. \ , . *\ \ \ i

PHP PROGRAMMING WITH MYSQL

PHP PROGRAMMING

WITH MYSQL

D O N G O S S E L I N , D I A N A K O K O S K A ,

R O B E R T E A S T E R B R O O K S

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States

S E C O N D E D I T I O N

; COURSE TECHNOLOGY *« CENGAGE Learning"

© 2011 Course Technology, Cengage Learning

ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means—graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act—without the prior written permission of the publisher.

Library of Congress Control Number: 2009940005

ISBN-13: 978-0-5387-4584-0 ISBN-10: 0-5387-4584-3

Course Technology 20 Channel Center Street Boston, MA 02210 USA

Cengage Learning is a leading provider of customized learning solutions with offi ce locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local offi ce at: www.cengage.com/global

Cengage Learning products are represented in Canada by Nelson Education, Ltd.

To learn more about Course Technology, visit www.cengage.com/coursetechnology

Purchase any of our products at your local college store or at our preferred online store www.CengageBrain.com

Some of the product names and company names used in this book have been used for identifi cation purposes only and may be trademarks or regis- tered trademarks of their respective manufacturers and sellers.

Course Technology, a part of Cengage Learning, reserves the right to revise this publication and make changes from time to time in its content without notice.

PHP Programming with MySQL, Second Edition Don Gosselin, Diana Kokoska, Robert Easterbrooks

Executive Editor: Marie Lee

Acquisitions Editor: Amy Jollymore

Managing Editor: Tricia Coia

Senior Product Manager: Alyssa Pratt

Developmental Editor: Dan Seiter

Content Project Manager: Jennifer Feltri

Editorial Assistant: Zina Kresin

Art Director: Marissa Falco

Text Designer: Shawn Girsberger

Cover Designer: Cabbage Design Company

Cover Image: © CSA Images

Print Buyer: Julio Esperas

Copy Editor: Camille Kiolbasa

Proofreader: Andrea Schein

Indexer: Alexandra Nickerson

Compositor: Integra

For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706

For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions

Further permissions questions can be e-mailed to [email protected]

Printed in the United States of America 1 2 3 4 5 6 7 13 12 11 10

* COURSE TECHNOLOGY CENGAGE Learning"

Brief Contents

Preface . . . . . . . . . . . . . . . . . xiv

CHAPTER 1 Gett ing Star ted wi th PHP . . . . . . . . . . 1

CHAPTER 2 Funct ions and Contro l Structures . . . . . . 74

CHAPTER 3 Manipulat ing Str ings . . . . . . . . . . . 124

CHAPTER 4 Handl ing User Input . . . . . . . . . . . 188

CHAPTER 5 Work ing wi th F i les and Director ies . . . . . 233

CHAPTER 6 Manipulat ing Arrays . . . . . . . . . . . 298

CHAPTER 7 Work ing wi th Databases and MySQL . . . . 380

CHAPTER 8 Manipulat ing MySQL Databases with PHP . . 446

CHAPTER 9 Managing State Informat ion . . . . . . . . 496

CHAPTER 10 Developing Object -Or iented PHP . . . . . . 556

APPENDIX A Work ing wi th XHTML . . . . . . . . . . . 620

APPENDIX B Conf igur ing a Personal Web Server . . . . 636

APPENDIX C Formatt ing Str ings. . . . . . . . . . . . 641

APPENDIX D Secure Coding with PHP . . . . . . . . . 648

APPENDIX E Error Handl ing and Debugging. . . . . . . 655

APPENDIX F Connect ing to SQL Server and Oracle Databases . . . . . . . . . . 671

Index . . . . . . . . . . . . . . . . . 679

v

Contents

Preface . . . . . . . . . . . . . . . . . xiv

CHAPTER 1 Gett ing Star ted wi th PHP . . . . . . . . . . 1

Creating Basic PHP Scripts . . . . . . . . . . . . . . . . . 2 Creating PHP Code Blocks . . . . . . . . . . . . . . . . . 3

Standard PHP Script Delimiters . . . . . . . . . . . . . . 3 The <script> Element . . . . . . . . . . . . . . . . . 6 Short PHP Script Delimiters . . . . . . . . . . . . . . . . 8 ASP-Style Script Delimiters . . . . . . . . . . . . . . . . 9 Understanding Functions . . . . . . . . . . . . . . . . .10 Displaying Script Results . . . . . . . . . . . . . . . . .12 Creating Multiple Code Declaration Blocks . . . . . . . . .17 Case Sensitivity in PHP . . . . . . . . . . . . . . . . . .20 Adding Comments to a PHP Script . . . . . . . . . . . . .20

Using Variables and Constants . . . . . . . . . . . . . . .22 Naming Variables . . . . . . . . . . . . . . . . . . . .23 Declaring and Initializing Variables . . . . . . . . . . . . .23 Displaying Variables . . . . . . . . . . . . . . . . . . .24 Modifying Variables . . . . . . . . . . . . . . . . . . .25 Defining Constants . . . . . . . . . . . . . . . . . . . .28

Working with Data Types . . . . . . . . . . . . . . . . . .30 Numeric Data Types . . . . . . . . . . . . . . . . . . .31 Boolean Values . . . . . . . . . . . . . . . . . . . . .33 Arrays . . . . . . . . . . . . . . . . . . . . . . . . .33 Avoiding Assignment Notation Pitfalls . . . . . . . . . . .40

Building Expressions . . . . . . . . . . . . . . . . . . . .40 Arithmetic Operators . . . . . . . . . . . . . . . . . . .41 Assignment Operators . . . . . . . . . . . . . . . . . .48 Comparison and Conditional Operators. . . . . . . . . . .51 Logical Operators . . . . . . . . . . . . . . . . . . . .55 Special Operators . . . . . . . . . . . . . . . . . . . .58 Type Casting . . . . . . . . . . . . . . . . . . . . . .59 Understanding Operator Precedence . . . . . . . . . . . .61

vi

Summing Up . . . . . . . . . . . . . . . . . . . . . . .63 Comprehension Check . . . . . . . . . . . . . . . . . . .65 Reinforcement Exercises . . . . . . . . . . . . . . . . . .68 Discovery Projects . . . . . . . . . . . . . . . . . . . . .72

CHAPTER 2 Funct ions and Contro l Structures . . . . . . 74

Working with Functions . . . . . . . . . . . . . . . . . . .75 Defining Functions . . . . . . . . . . . . . . . . . . . .75 Calling Functions. . . . . . . . . . . . . . . . . . . . .77 Returning Values . . . . . . . . . . . . . . . . . . . . .78

Understanding Variable Scope . . . . . . . . . . . . . . .82 The global Keyword . . . . . . . . . . . . . . . . . .82

Making Decisions . . . . . . . . . . . . . . . . . . . . .83 if Statements . . . . . . . . . . . . . . . . . . . . .84 if . . . else Statements . . . . . . . . . . . . . . . .87 Nested if and if . . . else Statements . . . . . . . . .89 switch Statements . . . . . . . . . . . . . . . . . . .92

Repeating Code . . . . . . . . . . . . . . . . . . . . . .95 while Statements. . . . . . . . . . . . . . . . . . . .96 do . . . while Statements . . . . . . . . . . . . . . . 100 for Statements . . . . . . . . . . . . . . . . . . . . 103 foreach Statements . . . . . . . . . . . . . . . . . 105

Including Files . . . . . . . . . . . . . . . . . . . . . . 109 Summing Up . . . . . . . . . . . . . . . . . . . . . . 111 Comprehension Check . . . . . . . . . . . . . . . . . . 112 Reinforcement Exercises . . . . . . . . . . . . . . . . . 116 Discovery Projects . . . . . . . . . . . . . . . . . . . . 122

CHAPTER 3 Manipulat ing Str ings . . . . . . . . . . . 124

Constructing Text Strings. . . . . . . . . . . . . . . . . 125 Working with String Operators . . . . . . . . . . . . . 126 Adding Escape Characters and Sequences . . . . . . . . 128 Simple and Complex String Syntax . . . . . . . . . . . 131

Working with a Single String . . . . . . . . . . . . . . . 134 Counting Characters and Words in a String . . . . . . . . 134 Modifying the Case of a String . . . . . . . . . . . . . 135 Encoding and Decoding a String. . . . . . . . . . . . . 138 Other Ways to Manipulate a String . . . . . . . . . . . . 139

Working with Multiple Strings . . . . . . . . . . . . . . . 141 Finding and Extracting Characters and Substrings . . . . 141 Replacing Characters and Substrings . . . . . . . . . . 144 Dividing Strings into Smaller Pieces . . . . . . . . . . . 147

vii

C O N T E N T S

Converting between Strings and Arrays . . . . . . . . . 151 Comparing Strings . . . . . . . . . . . . . . . . . . . . 154

String Comparison Functions . . . . . . . . . . . . . . 156 Determining the Similarity of Two Strings . . . . . . . . 158 Determining if Words Are Pronounced Similarly . . . . . . 159

Working with Regular Expressions . . . . . . . . . . . . . 160 Writing Regular Expression Patterns . . . . . . . . . . . 161 Matching Any Character . . . . . . . . . . . . . . . . 162 Matching Characters at the Beginning or End of a String . 163 Matching Special Characters . . . . . . . . . . . . . . 163 Specifying Quantity . . . . . . . . . . . . . . . . . . 164 Specifying Subexpressions . . . . . . . . . . . . . . . 165 Defining Character Classes . . . . . . . . . . . . . . . 166 Matching Multiple Pattern Choices . . . . . . . . . . . . 169 Pattern Modifiers . . . . . . . . . . . . . . . . . . . 169

Summing Up . . . . . . . . . . . . . . . . . . . . . . 171 Comprehension Check . . . . . . . . . . . . . . . . . . 172 Reinforcement Exercises . . . . . . . . . . . . . . . . . 175 Discovery Projects . . . . . . . . . . . . . . . . . . . . 180

CHAPTER 4 Handl ing User Input . . . . . . . . . . . 188

Using Autoglobals . . . . . . . . . . . . . . . . . . . . 189 Building XHTML Web Forms . . . . . . . . . . . . . . . . 191

Adding an action Attribute . . . . . . . . . . . . . . 192 Adding a method Attribute . . . . . . . . . . . . . . . 192

Processing Form Data . . . . . . . . . . . . . . . . . . 194 Retrieving Submitted Data . . . . . . . . . . . . . . . 194

Handling Submitted Form Data . . . . . . . . . . . . . . 199 Determining if Form Variables Contain Values . . . . . . . 199 Validating Entered Data . . . . . . . . . . . . . . . . . 199 Handling Multiple Errors . . . . . . . . . . . . . . . . 201 Redisplaying the Web Form . . . . . . . . . . . . . . . 203 Using the Submitted Data . . . . . . . . . . . . . . . . 206

Creating an All-in-One Form . . . . . . . . . . . . . . . . 209 Validating an All-in-One Form . . . . . . . . . . . . . . 209 Processing the Web Form. . . . . . . . . . . . . . . . 210 Redisplaying the Web Form . . . . . . . . . . . . . . . 210

Displaying Dynamic Content Based on a URL Token . . . . . 212 Using a Web Page Template. . . . . . . . . . . . . . . 212 Navigating within a Web Page Template . . . . . . . . . 214 Displaying the Dynamic Content . . . . . . . . . . . . . 214

Summing Up . . . . . . . . . . . . . . . . . . . . . . 218 Comprehension Check . . . . . . . . . . . . . . . . . . 219

viii

C O N T E N T S

Reinforcement Exercises . . . . . . . . . . . . . . . . . 221 Discovery Projects . . . . . . . . . . . . . . . . . . . . 229

CHAPTER 5 Work ing wi th F i les and Director ies . . . . . 233

Understanding File Types and Permissions . . . . . . . . . 234 Understanding File Types . . . . . . . . . . . . . . . . 234 Working with File Permissions . . . . . . . . . . . . . . 236

Working with Directories . . . . . . . . . . . . . . . . . 238 Reading Directories . . . . . . . . . . . . . . . . . . 238 Creating Directories . . . . . . . . . . . . . . . . . . 241 Obtaining File and Directory Information . . . . . . . . . 242

Uploading and Downloading Files . . . . . . . . . . . . . 247 Uploading Files . . . . . . . . . . . . . . . . . . . . 247 Downloading Files . . . . . . . . . . . . . . . . . . . 252

Reading and Writing Entire Files . . . . . . . . . . . . . . 257 Writing an Entire File . . . . . . . . . . . . . . . . . . 257 Reading an Entire File . . . . . . . . . . . . . . . . . 262

Opening and Closing File Streams . . . . . . . . . . . . . 267 Opening a File Stream . . . . . . . . . . . . . . . . . 267 Closing a File Stream. . . . . . . . . . . . . . . . . . 270 Writing Data Incrementally . . . . . . . . . . . . . . . 270 Locking Files . . . . . . . . . . . . . . . . . . . . . 272 Reading Data Incrementally . . . . . . . . . . . . . . . 275

Managing Files and Directories . . . . . . . . . . . . . . 278 Copying and Moving Files . . . . . . . . . . . . . . . . 278 Renaming Files and Directories . . . . . . . . . . . . . 280 Removing Files and Directories . . . . . . . . . . . . . 281

Summing Up . . . . . . . . . . . . . . . . . . . . . . 283 Comprehension Check . . . . . . . . . . . . . . . . . . 285 Reinforcement Exercises . . . . . . . . . . . . . . . . . 288 Discovery Projects . . . . . . . . . . . . . . . . . . . . 292

CHAPTER 6 Manipulat ing Arrays . . . . . . . . . . . 298

Manipulating Elements . . . . . . . . . . . . . . . . . . 299 Adding and Removing Elements from the Beginning

of an Array . . . . . . . . . . . . . . . . . . . . . 304 Adding and Removing Elements from the End of an Array . 308 Adding and Removing Elements Within an Array . . . . . . 310 Removing Duplicate Elements . . . . . . . . . . . . . . 314

Declaring and Initializing Associative Arrays . . . . . . . . 316 Iterating Through an Array . . . . . . . . . . . . . . . . 323 Finding and Extracting Elements and Values . . . . . . . . 328

ix

C O N T E N T S

Determining if a Value Exists . . . . . . . . . . . . . . 328 Determining if a Key Exists . . . . . . . . . . . . . . . 333 Returning a Portion of an Array . . . . . . . . . . . . . 334

Manipulating Arrays . . . . . . . . . . . . . . . . . . . 336 Sorting Arrays . . . . . . . . . . . . . . . . . . . . . 336 Combining Arrays . . . . . . . . . . . . . . . . . . . 343 Comparing Arrays . . . . . . . . . . . . . . . . . . . 348

Understanding Multidimensional Arrays . . . . . . . . . . 350 Creating Two-Dimensional Indexed Arrays . . . . . . . . 351 Creating Two-Dimensional Associative Arrays . . . . . . . 355 Creating Multidimensional Arrays with

a Single Statement . . . . . . . . . . . . . . . . . . 356 Working with Additional Dimensions . . . . . . . . . . . 357

Using Arrays in Web Forms . . . . . . . . . . . . . . . . 359 Summing Up . . . . . . . . . . . . . . . . . . . . . . 365 Comprehension Check . . . . . . . . . . . . . . . . . . 366 Reinforcement Exercises . . . . . . . . . . . . . . . . . 369 Discovery Projects . . . . . . . . . . . . . . . . . . . . 376

CHAPTER 7 Work ing wi th Databases and MySQL . . . . 380

Introduction to Databases . . . . . . . . . . . . . . . . 381 Understanding Table Relationships . . . . . . . . . . . . 382 Working with Database Management Systems . . . . . . 388 Querying Databases with Structured Query

Language (SQL) . . . . . . . . . . . . . . . . . . . 390 Getting Started with MySQL . . . . . . . . . . . . . . . 392

Logging in to MySQL . . . . . . . . . . . . . . . . . . 392 Working with MySQL Monitor . . . . . . . . . . . . . . 394 Understanding MySQL Identifiers . . . . . . . . . . . . 395 Getting Help with MySQL Commands . . . . . . . . . . . 396

Working with MySQL Databases . . . . . . . . . . . . . . 399 Creating Databases . . . . . . . . . . . . . . . . . . 399 Selecting a Database. . . . . . . . . . . . . . . . . . 400 Deleting Databases . . . . . . . . . . . . . . . . . . 401

Defining Database Tables . . . . . . . . . . . . . . . . . 402 Specifying Field Data Types . . . . . . . . . . . . . . . 402 Creating Tables . . . . . . . . . . . . . . . . . . . . 404 Altering Tables. . . . . . . . . . . . . . . . . . . . . 406 Deleting Tables . . . . . . . . . . . . . . . . . . . . 408

Modifying User Privileges . . . . . . . . . . . . . . . . . 408 Granting Privileges . . . . . . . . . . . . . . . . . . . 409 Revoking Privileges . . . . . . . . . . . . . . . . . . 411

x

C O N T E N T S

Working with Database Records . . . . . . . . . . . . . . 412 Adding Records . . . . . . . . . . . . . . . . . . . . 412 Retrieving Records . . . . . . . . . . . . . . . . . . . 415 Using Aggregate Functions . . . . . . . . . . . . . . . 418 Sorting Query Results . . . . . . . . . . . . . . . . . 421 Filtering Query Results . . . . . . . . . . . . . . . . . 423 Updating Records . . . . . . . . . . . . . . . . . . . 425 Deleting Records . . . . . . . . . . . . . . . . . . . 427

Working with phpMyAdmin . . . . . . . . . . . . . . . . 428 Logging in to phpMyAdmin . . . . . . . . . . . . . . . 428 Working with Databases . . . . . . . . . . . . . . . . 431 Working with Tables . . . . . . . . . . . . . . . . . . 432 Exporting and Importing Tables . . . . . . . . . . . . . 432

Summing Up . . . . . . . . . . . . . . . . . . . . . . 433 Comprehension Check . . . . . . . . . . . . . . . . . . 435 Reinforcement Exercises . . . . . . . . . . . . . . . . . 438 Discovery Projects . . . . . . . . . . . . . . . . . . . . 443

CHAPTER 8 Manipulat ing MySQL Databases with PHP . . 446

Connecting to MySQL with PHP . . . . . . . . . . . . . . 448 Determining which MySQL Package to Use . . . . . . . . 448 Opening and Closing a MySQL Connection . . . . . . . . 448 Reporting MySQL Errors . . . . . . . . . . . . . . . . 451 Suppressing Errors with the Error Control Operator . . . . 452

Working with MySQL Databases . . . . . . . . . . . . . . 453 Creating a Database . . . . . . . . . . . . . . . . . . 453 Selecting a Database. . . . . . . . . . . . . . . . . . 455 Deleting a Database . . . . . . . . . . . . . . . . . . 458

Working with Tables . . . . . . . . . . . . . . . . . . . 459 Using mysql_query() . . . . . . . . . . . . . . . . 459 Creating and Deleting Tables . . . . . . . . . . . . . . 460

Manipulating Records . . . . . . . . . . . . . . . . . . 464 Adding, Deleting, and Updating Records . . . . . . . . . 464 Returning Information on Affected Records . . . . . . . . 469

Retrieving Records. . . . . . . . . . . . . . . . . . . . 473 Working with Query Results . . . . . . . . . . . . . . . 473 Closing Query Results . . . . . . . . . . . . . . . . . 479 Accessing Query Result Information . . . . . . . . . . . 479

Summing Up . . . . . . . . . . . . . . . . . . . . . . 482 Comprehension Check . . . . . . . . . . . . . . . . . . 483 Reinforcement Exercises . . . . . . . . . . . . . . . . . 487 Discovery Projects . . . . . . . . . . . . . . . . . . . . 493

xi

C O N T E N T S

CHAPTER 9 Managing State Informat ion . . . . . . . . 496

Understanding State Information . . . . . . . . . . . . . 497 Using Hidden Form Fields to Save State Information . . . . 506 Using Query Strings to Save State Information . . . . . . . 515 Using Cookies to Save State Information . . . . . . . . . . 517

Creating Cookies . . . . . . . . . . . . . . . . . . . 518 The name and value Arguments . . . . . . . . . . . . 519 The expires Argument . . . . . . . . . . . . . . . . 521 The path Argument . . . . . . . . . . . . . . . . . . 525 The domain Argument . . . . . . . . . . . . . . . . . 525 The secure Argument . . . . . . . . . . . . . . . . . 526 Reading Cookies . . . . . . . . . . . . . . . . . . . . 526 Deleting Cookies . . . . . . . . . . . . . . . . . . . . 529

Using Sessions to Save State Information . . . . . . . . . 530 Starting a Session . . . . . . . . . . . . . . . . . . . 531 Working with Session Variables . . . . . . . . . . . . . 532 Deleting a Session . . . . . . . . . . . . . . . . . . . 536

Summing Up . . . . . . . . . . . . . . . . . . . . . . 538 Comprehension Check . . . . . . . . . . . . . . . . . . 539 Reinforcement Exercises . . . . . . . . . . . . . . . . . 542 Discovery Projects . . . . . . . . . . . . . . . . . . . . 548

CHAPTER 10 Developing Object -Or iented PHP . . . . . . 556

Introduction to Object-Oriented Programming . . . . . . . . 557 Understanding Encapsulation . . . . . . . . . . . . . . 559 Object-Oriented Programming and Classes . . . . . . . . 560

Using Objects in PHP Script . . . . . . . . . . . . . . . 563 Working with Database Connections as Objects . . . . . . 565 Defining Custom PHP Classes . . . . . . . . . . . . . . 573 Collecting Garbage. . . . . . . . . . . . . . . . . . . 578

Declaring Data Members . . . . . . . . . . . . . . . . . 578 What Is Information Hiding? . . . . . . . . . . . . . . . 579 Using Access Specifiers . . . . . . . . . . . . . . . . 580 Serializing Objects . . . . . . . . . . . . . . . . . . . 582

Working with Member Functions . . . . . . . . . . . . . . 584 Using the $this Reference. . . . . . . . . . . . . . . 585 Initializing with Constructor Functions . . . . . . . . . . 585 Cleaning Up with Destructor Functions . . . . . . . . . . 587 Writing Accessor and Mutator Functions . . . . . . . . . 588 Serialization Functions . . . . . . . . . . . . . . . . . 594

Summing Up . . . . . . . . . . . . . . . . . . . . . . 600 Comprehension Check . . . . . . . . . . . . . . . . . . 601

xii

C O N T E N T S

Reinforcement Exercises . . . . . . . . . . . . . . . . . 604 Discovery Projects . . . . . . . . . . . . . . . . . . . . 611

APPENDIX A Work ing wi th XHTML . . . . . . . . . . . 620

APPENDIX B Conf igur ing a Personal Web Server . . . . 636

APPENDIX C Formatt ing Str ings. . . . . . . . . . . . 641

APPENDIX D Secure Coding with PHP . . . . . . . . . 648

APPENDIX E Error Handl ing and Debugging. . . . . . . 655

APPENDIX F Connect ing to SQL Server and Oracle Databases . . . . . . . . . . 671

Index . . . . . . . . . . . . . . . . . 679

xiii

C O N T E N T S

Preface

PHP: Hypertext Preprocessor, or PHP, is an open source program- ming language that is used for developing interactive Web sites. More specifi cally, PHP is a scripting language that is executed from a Web server. Created in 1995, PHP is one of the fastest-growing program- ming languages today. � e TIOBE Programming Community Index1 ranked PHP as the third most popular programming language in the world.

One of the primary reasons for PHP’s popularity is its simplicity. � e language is relatively easy to learn, allowing new programmers to quickly incorporate PHP functionality into a Web site. MySQL is an open source relational database that is often used with PHP. Together, PHP and MySQL are becoming one of the most popular technology combinations for Web site development.

PHP is a dynamic, growing language with new functionality added on a regular basis. PHP is supported by a community of developers and users who add features and contribute updates that expand the functionality of the code. � e PHP Group coordinates the develop- ment eff orts of more than 400 user groups in more than 80 countries. Although the PHP Group does not impose formal specifi cations, it does issue recommendations for how PHP should and should not be used. Complete documentation for all versions of the PHP language is available at www.php.net. You should bookmark this site, because it will become your primary point of reference as you progress through this book.

PHP Programming with MySQL teaches Web development with PHP and MySQL for students with little programming or database experience, although knowledge of XHTML and Web page design is helpful. � is book covers the basics of PHP and MySQL along with introductions to advanced topics, including object-oriented program- ming and how to build Web sites that incorporate authentication and security. After you complete this course, you will be able to use PHP and MySQL to build professional-quality, database-driven Web sites.

Appendix A provides a refresher on scripting in XHTML,

validating XHTML code (including an explanation of the Strict DTD), and formatting with Cascading Style Sheets (CSS).

1 � e TIOBE Programming Community Index at http://www.tiobe.com/index.php/content/ paperinfo/tpci/index.html for September 2009.

xiv

The Approach � is book introduces a variety of techniques, focusing on what you need to know to start writing PHP scripts. In each chapter, you build and create PHP scripts using the new concepts introduced in the chapter. Each chapter ends with a chapter summary, review ques- tions, Reinforcement Exercises, and Discovery Projects that highlight major concepts and let you apply the concepts you have learned. � e Reinforcement Exercises include both guided and free-form exercises that reinforce the skills you learn in the chapter and provide addi- tional ways to apply your knowledge in new situations. At the end of each chapter, you will also complete Discovery Projects to apply the skills you learned in the chapter and expand the functionality of an ongoing comprehensive Web site project.

Overview of …