You are previewing Negus Live Linux Series Practical PHP and MySQL.
O'Reilly logo
Negus Live Linux Series Practical PHP and MySQL

Book 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 that make you 'hide behind the couch.'"
-From the Foreword by Christopher Negus, Series Editor, Negus Live Linux Series


Build Dynamic Web Sites Fast, with PHP and MySQL...

Learn from Eight Ready-to-Run Applications!

Suddenly, it’s easy to build commercial-quality Web applications using free and open source software. With this book, you’ll learn from eight ready-to-run, real-world applications—all backed by clear diagrams and screenshots, well-documented code, and simple, practical explanations.

Leading open source author Jono Bacon teaches the core skills you’ll need to build virtually any application. You’ll discover how to connect with databases, upload content, perform cascading deletes, edit records, validate registrations, specify user security, create reusable components, use PEAR extensions, and even build Ajax applications.

Working from complete examples on the CD-ROM, you’ll create

  • Generic dynamic Web sites

  • Blogs

  • Discussion forums

  • Shopping carts

  • Auction sites

  • Calendars

  • FAQ systems

  • Reusable components

  • Content management systems

  • News sites

JONO BACON is Ubuntu community manager for Canonical, Ubuntu’s sponsor. He is an established speaker, author, and contributor to the open source community. Bacon co-authored Linux Desktop Hacks and The Official Ubuntu Book; has served as a columnist for Linux Format, Linux User & Developer, and PC Plus; and is an O’Reilly Networkweblog author. He is a lead developer onthe Jokosher (www.jokosher.org) project,and co-founder of LUGRadio—a podcastwith more than 15,000 listeners, andan annual event that attracts visitorsfrom around the world.

CD-ROM Includes

  • XAMPP for Linux: easy-to-install, preconfigured Apache distributions containing MySQL, PHP, Perl, and more

  • Source code for all eight fully-working applications discussed in the book

  • A remastered Ubuntu live CD, set to run all eight applications live

System Requirements

  • CPU: Pentium III, 650 MHz. RAM: 256MB (recommended 512MB).

  • Hard disk: No space required to run live CD; 250MB of space needed to put XAMPP server and projects on installed system.

Table of Contents

  1. Copyright
    1. Dedication
  2. Negus Live Linux Series
  3. Foreword
  4. About the Author
  5. Acknowledgments
  6. Introduction
    1. A Different Approach
    2. What You Need to Use This Book
    3. Conventions
    4. Onward
  7. 1. A New Approach
    1. The Technology
      1. PHP
      2. MySQL
    2. How the Dynamic Web Works
    3. Summary
  8. 2. Getting Started with PHP and MySQL
    1. Setting Up PHP and MySQL
      1. Setting Up XAMPP on Windows
      2. Setting Up XAMPP on Linux
    2. Getting Started with PHP
      1. Using Variables
        1. PHP as a Simple Calculator
      2. Arrays
      3. Loops
        1. The for Loop
        2. The while Loop
      4. Ask Questions of Your Code
        1. The if Statement
        2. The switch Statement
      5. Using Functions
      6. Working with Forms
        1. Processing the Form
    3. Rolling in MySQL
      1. An Example: Product Database
        1. Designing the Table Structure
        2. How the Tables Relate to Each Other
        3. Creating the Database
        4. Creating the Tables
        5. Adding Data to the Tables
    4. Connecting to MySQL in PHP
      1. Making the Connection
        1. Querying the Database
        2. Iterating Through the Results
      2. Consistency Across Pages with Sessions
        1. Creating the Session
        2. Using Session Variables
    5. Summary
  9. 3. Running the Projects
    1. About the Disc
      1. Live CDs: A New Approach
      2. Starting the System
    2. Running the Applications
    3. Using XAMPP
      1. Starting and Stopping
      2. Accessing phpMyAdmin
      3. Switching PHP Versions
      4. Backing Up
    4. Summary
  10. 4. Building a Weblog
    1. Project Overview: Blogtastic Use Case
    2. Building the Database
      1. Implementing the Database
        1. The categories Table
        2. The entries Table
        3. The comments Table
        4. The logins Table
      2. Inserting Sample Data
        1. Sample Data for the categories Table
        2. Sample Data for the entries Table
        3. Sample Data for the comments Table
        4. Sample Data for the logins Table
    3. Starting to Code
      1. Designing a User Interface
        1. Creating the Header File
        2. Creating the Footer File
      2. Displaying a Blog Entry
        1. Building the Query
        2. Displaying the Entry
      3. Adding a Comments Summary
      4. Displaying Previous Blog Entries
    4. Viewing Specific Entries
      1. Validating the Request URL
      2. Showing the Entry
      3. Showing Blog Comments
      4. Build the Comment Form
    5. Building the Category Browser
    6. Don’t Just Let Anyone Log In
      1. Signing Out the User
      2. Adding Session Support to the Application
        1. Bolting On Options in the Header File
        2. Adding Links to Update Blog Entries
    7. Rolling Your Own Categories
    8. Creating New Blog Entries
    9. Update a Blog Entry
    10. Summary
  11. 5. Discussion Forums
    1. Under the Hood
    2. Building Your Own Forums
    3. Before You Begin
    4. Creating the Database
      1. Enforcing Relationships with InnoDB
      2. Building the Database
        1. The admins Table
        2. The categories Table
        3. The forums Table
        4. The messages Table
        5. The topics Table
        6. The users Table
      3. Adding Sample Data to the Database
        1. The users Table
        2. The categories Table
        3. The forums Table
        4. The topics Table
        5. The messages Table
    5. Creating the Site Design
    6. Displaying the Forums
      1. Creating the Front Page
      2. Viewing Forum Topics
      3. Viewing a Thread
    7. Managing User Logins
      1. User Registrations
      2. Verifying the Account
      3. Logging In Users
      4. Logging In the Administrator
      5. Logging Out
    8. Posts and Replies
      1. Posting a New Topic
      2. Replying to Threads
    9. Creating Administrator-Specific Pages
      1. Adding Categories
      2. Adding Forums
      3. Deleting
    10. Summary
  12. 6. Creating a Shopping Cart
    1. Project Overview
    2. Building the Database
      1. Implementing the Database
      2. The admins Table
      3. The categories Table
      4. The customers Table
      5. The delivery_addresses Table
      6. The logins Table
      7. The orderitems Table
      8. The orders Table
      9. The products Table
      10. Insert Sample Data
        1. Sample Data for the admins Table
        2. Sample Data for the categories Table
        3. Sample Data for the customers Table
        4. Sample Data for the logins Table
        5. Sample Data for the delivery_addresses Table
        6. Sample Data for the products Table
        7. Sample Data for the orders Table
        8. Sample Data for the orderitems Table
    3. Starting to Code
    4. Managing User Logins
      1. Logging Out Users
    5. Displaying and Selecting Products
      1. Adding the Item to the Cart
      2. Displaying the Basket Summary
      3. Deleting Items
    6. Checking It Out
      1. Paying
    7. Administrator Pages
      1. Logging Out the Administrator
      2. Managing Completed Orders
      3. Viewing a Specific Order
    8. Summary
  13. 7. Building an Online Auction Site
    1. Project Overview
    2. Building the Database
      1. Implementing the Database
        1. The categories Table
        2. The users Table
        3. The items Table
        4. The bids Table
        5. The images Table
      2. Insert Sample Data
        1. Sample Data for the categories Table
        2. Sample Data for the items Table
        3. Sample Data for the users Table
        4. Sample Data for the bids and images Tables
    3. Starting to Code
    4. Displaying Auction Items
      1. Displaying the Categories
      2. Viewing the Items in a Category
      3. Viewing Item Details and Placing Bids
    5. Dealing with Users
      1. Logging Out
      2. User Registration
    6. Adding an Item
      1. Adding the Images
      2. Deleting an Image
    7. Processing Auctions
    8. Scheduling the Page to Be Run
    9. Summary
  14. 8. Creating a Web-Based Calendar
    1. Project Overview
    2. Building the Database
      1. Implementing the Database
        1. The events Table
        2. The logins Table
      2. Insert Sample Data
        1. Sample Data for the events Table
        2. Sample Data for the logins Table
    3. Starting to Code
      1. Site Layout and Style
      2. Building the Login Screen
    4. Viewing Events
      1. All About Ajax
        1. How Ajax Works
      2. Creating the Sidebar
        1. Dealing with Dates
        2. Preparing for Ajax
        3. Displaying Upcoming Events
      3. The Calendar View
      4. Fill In the Ajax Functionality
        1. Viewing Event Information
        2. Adding a New Event
      5. Deleting Events
    5. Summary
  15. 9. FAQ Content Management System
    1. Project Overview
    2. Building the Database
      1. Implementing the Database
        1. The admins Table
        2. The comments Table
        3. The mod_subowner Table
        4. The questions Table
        5. The subjects Table
        6. The topics Table
        7. The users Table
      2. Creating the Table Relationships
      3. Inserting Sample Data
        1. Sample Data for the admins Table
        2. Sample Data for the users Table
        3. Sample Data for the subjects, topics, questions, and comments Tables
        4. Sample Data for the mod_subowner Table
    3. Starting to Code
      1. A More Involved Sidebar
      2. Creating the Functions
      3. Building the Main Page
    4. Displaying Questions
      1. Displaying Question Summary
      2. Showing a Specific Question
        1. Updating the Sidebar
    5. Dealing with Logins
      1. Normal User Logins
        1. Displaying the Control Panel
        2. Logging Out
        3. Adding Feedback in the Sidebar
      2. Administrator Logins
        1. Logout
        2. Becoming an Admin and Playing With More Toys
        3. Adding More Feedback to That Sidebar
    6. Adding and Moderating Questions
      1. Adding Questions
      2. Affirm Some Power and Moderate Some Questions
        1. The main Block
        2. The details Block
        3. The allow Block
        4. The deny Block
        5. The denyconf Block
    7. Managing Subjects
      1. Adding Subjects
      2. Deleting Subjects
    8. Managing Topics
      1. Adding Topics
      2. Getting Rid of Topics
    9. Subject Ownership
      1. Applying for Ownership of a Subject
      2. Moderating Ownership Requests
        1. The main Block
        2. The accept Block
        3. The deny Block
        4. The denyconf Block
      3. Removing Ownership
    10. Summary
  16. 10. Building a Re-Usable Project
    1. Project Overview
    2. Building the Database
      1. Implementing the Database
        1. The homeproject_projects Table
        2. The homeproject_releaseversions Table
        3. The homeproject_releasetypes Table
        4. The homeproject_releasefiles Table
        5. The homeproject_screenshots Table
      2. Inserting Sample Data
        1. Sample Data for the homeproject_projects Table
        2. Sample Data for the homeproject_releaseversions Table
        3. Sample Data for the homeproject_releasetypes Table
        4. Sample Data for the homeproject_releasefiles Table
        5. Sample Data for the homeproject_screenshots Table
    3. Using Directories Intelligently
      1. Creating the Directories
    4. Starting to Code: Building the Backbone
      1. Accessing the Database
      2. Creating the Functions
      3. The Main Project
      4. Viewing Menu Options
      5. Accessing the Project’s Features
    5. Downloading Releases
    6. Viewing Screenshots
    7. Available Projects Viewer
    8. Administering Projects
    9. Changing General Settings
    10. Managing Downloads
    11. Deleting Releases
    12. Managing Screenshots
    13. Deleting Images
    14. Adding a New Project
    15. Deploying the Application
    16. Summary
  17. 11. Building a News Web Site
    1. Project Overview
    2. Installing PEAR Packages
    3. Building the Database
      1. Implementing the Database
        1. The categories Table
        2. The cat_relate Table
        3. The users Table
        4. The stories Table
        5. The ratings Table
      2. Inserting Sample Data
        1. Sample Data for the categories Table
        2. Sample Data for the cat_relate Table
        3. Sample Data for the users Table
        4. Sample Data for the stories Table
        5. Sample Data for the ratings Table
    4. Starting to Code
      1. Building the Menu Structure
      2. Creating the Main Page
    5. Handling User Logins
      1. Logging Out Users
      2. Updating the Sidebar
    6. Viewing and Rating Stories
      1. Performing the Rating
    7. Managing Stories
      1. Adding Stories
      2. Deleting Stories
    8. Managing Categories
      1. Deleting Categories
    9. Creating Your Search Engine
    10. Summary
  18. A. Web Site Design
    1. Project Overview
    2. Laying Out the Site
    3. Starting to Code
      1. id Versus class
    4. Start Building the Stylesheet
    5. Formatting the Main <div> Items
      1. The Header
      2. The Menu
      3. Styling the Container and Content
        1. Styling the Side Bar
        2. Styling the Main Body of the Page
    6. Creating an About Page
    7. Creating a Frequently Asked Questions Page
    8. Formatting Tables
    9. Summary