ebook img

Practical PHP and MySQL(R): Building Eight Dynamic Web Applications (Negus Live Linux Series) PDF

527 Pages·2006·6.25 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Practical PHP and MySQL(R): Building Eight Dynamic Web Applications (Negus Live Linux Series)

Practical PHP and MySQL ® N E G U S L I V E L I N U X S E R I E S Your practical, hands-on guides to getting real results with free software Books in the Negus Live Linux Series encourage and challenge you to advance in the free software world. Boot the live DVD or CD that comes with each book and watch the Linux system, applications, and content described in the book come to life before your eyes. Start as a novice by trying out examples and finish as a profes- sional, mastering the many topics covered in the series, from building PHP/MySQL sites to customizing live CDs and more. When you are finished, you will know how to use, customize, and rebuild that free and open source software yourself. Overseeing the series is Christopher Negus, bestselling author of the Red Hat Linux Bible series, Linux Toys series, and the signature book for this series, Live Linux CDs. N E G U S L I V E L I N U X S E R I E S Practical PHP and MySQL ® Building Eight Dynamic Web Applications Jono Bacon Upper Saddle River, NJ ■Boston■Indianapolis■San Francisco New York ■Toronto ■Montreal■London■Munich■Paris■Madrid Cape Town ■Sydney■Tokyo ■Singapore■Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trade- mark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the United States, please contact: International Sales [email protected] Visit us on the Web: www.prenhallprofessional.com Library of Congress Cataloging-in-Publication Data Bacon, Jono. Practical PHP and MySQL : building eight dynamic web applications / Jono Bacon. p. cm. Includes index. ISBN 0-13-223997-3 (pbk. : alk. paper) 1. PHP (Computer program language) 2. MySQL (Electronic resource) 3. Web site development. I. Title. TK5105.888.B325 2007 005.13’3—dc22 2006027701 Copyright © 2007 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department 75 Arlington Street, Suite 300 Boston, MA 02116 Fax: (617) 848-7047 ISBN 0-13-223997-3 Text printed in the United States on recycled paper at R. R. Donnelley in Crawfordsville, Indiana. First printing: November 2006 To my family for their never-ending support… This page intentionally left blank Contents Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 A Different Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What You Need to Use This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Onward. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 CHAPTER 1 A New Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 The Technology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 How the Dynamic Web Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 CHAPTER 2 Getting Started with PHP and MySQL . . . . . . . . . . . . . 15 Setting Up PHP and MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Getting Started with PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Rolling in MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Connecting to MySQL in PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 vii viii Contents CHAPTER 3 Running the Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . 53 About the Disc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Running the Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Using XAMPP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 CHAPTER 4 Building a Weblog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Project Overview: Blogtastic Use Case . . . . . . . . . . . . . . . . . . . . . . 64 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Starting to Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Viewing Specific Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Building the Category Browser. . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Don’t Just Let Anyone Log In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Rolling Your Own Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Creating New Blog Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Update a Blog Entry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 CHAPTER 5 Discussion Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Under the Hood. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Building Your Own Forums. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Creating the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Creating the Site Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Displaying the Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Managing User Logins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Posts and Replies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Creating Administrator-Specific Pages. . . . . . . . . . . . . . . . . . . . . 158 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 CHAPTER 6 Creating a Shopping Cart . . . . . . . . . . . . . . . . . . . . . . 169 Project Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Starting to Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Managing User Logins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Displaying and Selecting Products . . . . . . . . . . . . . . . . . . . . . . . . 184 Checking It Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 Administrator Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Contents ix CHAPTER 7 Building an Online Auction Site. . . . . . . . . . . . . . . . . . 219 Project Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Starting to Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Displaying Auction Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Dealing with Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Adding an Item. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Processing Auctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 Scheduling the Page to Be Run. . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 CHAPTER 8 Creating a Web-Based Calendar . . . . . . . . . . . . . . . . . 265 Project Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Starting to Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Viewing Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 CHAPTER 9 FAQ Content Management System . . . . . . . . . . . . . . . 303 Project Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Starting to Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Displaying Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 Dealing with Logins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 Adding and Moderating Questions . . . . . . . . . . . . . . . . . . . . . . . 341 Managing Subjects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Managing Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Subject Ownership. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 CHAPTER 10 Building a Re-Usable Project. . . . . . . . . . . . . . . . . . . . 379 Project Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 Building the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Using Directories Intelligently. . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 Starting to Code: Building the Backbone. . . . . . . . . . . . . . . . . . . 386 Downloading Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 Viewing Screenshots. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 Available Projects Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

Description:
"Practical PHP and MySQL reflects Jono's commitment to the spirit of making open source subjects accessible to everyone. The book carefully walks you through the code for eight useful, dynamic Web applications. Projects are presented in a playful way, like the forum project that touts horror movies
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.