You are previewing PHP Solutions: Dynamic Web Design Made Easy, Second Edition.
O'Reilly logo
PHP Solutions: Dynamic Web Design Made Easy, Second Edition

Book Description

This is the second edition of David Power's highly-respected PHP Solutions: Dynamic Web Design Made Easy. This new edition has been updated by David to incorporate changes to PHP since the first edition and to offer the latest techniques--a classic guide modernized for 21st century PHP techniques, innovations, and best practices.

You want to make your websites more dynamic by adding a feedback form, creating a private area where members can upload images that are automatically resized, or perhaps storing all your content in a database. The problem is, you're not a programmer and the thought of writing code sends a chill up your spine. Or maybe you've dabbled a bit in PHP and MySQL, but you can't get past baby steps. If this describes you, then you've just found the right book. PHP and the MySQL database are deservedly the most popular combination for creating dynamic websites. They're free, easy to use, and provided by many web hosting companies in their standard packages.

Unfortunately, most PHP books either expect you to be an expert already or force you to go through endless exercises of little practical value. In contrast, this book gives you real value right away through a series of practical examples that you can incorporate directly into your sites, optimizing performance and adding functionality such as file uploading, email feedback forms, image galleries, content management systems, and much more. Each solution is created with not only functionality in mind, but also visual design.

But this book doesn't just provide a collection of ready-made scripts: each PHP Solution builds on what's gone before, teaching you the basics of PHP and database design quickly and painlessly. By the end of the book, you'll have the confidence to start writing your own scripts or--if you prefer to leave that task to others--to adapt existing scripts to your own requirements. Right from the start, you're shown how easy it is to protect your sites by adopting secure coding practices.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewers
  4. Acknowledgments
  5. Introduction
    1. Using the example files
    2. Layout conventions
  6. 1. What Is PHP—And Why Should I Care?
    1. 1.1. How PHP has grown
    2. 1.2. How PHP makes pages dynamic
      1. 1.2.1. Creating pages that think for themselves
    3. 1.3. How hard is PHP to use and learn?
      1. 1.3.1. Can I just copy and paste the code?
      2. 1.3.2. How safe is PHP?
    4. 1.4. What software do I need to write PHP?
      1. 1.4.1. What to look for when choosing a PHP editor
        1. 1.4.1.1. General purpose web development tools with PHP support
        2. 1.4.1.2. Dedicated script editors
    5. 1.5. So, let's get on with it . . .
  7. 2. Getting Ready to Work with PHP
    1. 2.1. Checking whether your website supports PHP
      1. 2.1.1. Deciding where to test your pages
    2. 2.2. What you need for a local test environment
      1. 2.2.1. Individual programs or an all-in-one package?
    3. 2.3. Setting up on Windows
      1. 2.3.1. Getting Windows to display filename extensions
      2. 2.3.2. Choosing a web server
      3. 2.3.3. Installing XAMPP on Windows
        1. 2.3.3.1. Troubleshooting
        2. 2.3.3.2. Configuring XAMPP
        3. 2.3.3.3. Starting Apache and MySQL automatically with XAMPP
      4. 2.3.4. Installing PHP with the Microsoft Web Platform Installer
        1. 2.3.4.1. Installing MySQL separately (for IIS only)
        2. 2.3.4.2. Installing phpMyAdmin separately (for IIS only)
    4. 2.4. Setting up on Mac OS X
      1. 2.4.1. Installing MAMP
      2. 2.4.2. Testing and configuring MAMP
    5. 2.5. Checking your PHP settings (Windows and Mac)
      1. 2.5.1. Eliminating magic quotes
      2. 2.5.2. Editing php.ini
    6. 2.6. Where to locate your PHP files
    7. 2.7. What's next?
  8. 3. How to Write PHP Scripts
    1. 3.1. PHP: The big picture
      1. 3.1.1. Telling the server to process PHP
      2. 3.1.2. Embedding PHP in a web page
      3. 3.1.3. Storing PHP in an external file
      4. 3.1.4. Using variables to represent changing values
        1. 3.1.4.1. Naming variables
        2. 3.1.4.2. Assigning values to variables
      5. 3.1.5. Ending commands with a semicolon
      6. 3.1.6. Commenting scripts
        1. 3.1.6.1. Single-line comments
        2. 3.1.6.2. Multiline comments
      7. 3.1.7. Using arrays to store multiple values
      8. 3.1.8. PHP's built-in superglobal arrays
      9. 3.1.9. Understanding when to use quotes
        1. 3.1.9.1. Special cases: true, false, and null
      10. 3.1.10. Making decisions
      11. 3.1.11. Making comparisons
      12. 3.1.12. Using indenting and whitespace for clarity
      13. 3.1.13. Using loops for repetitive tasks
      14. 3.1.14. Using functions for preset tasks
      15. 3.1.15. Understanding PHP classes and objects
      16. 3.1.16. Displaying PHP output
        1. 3.1.16.1. Joining strings together
        2. 3.1.16.2. Working with numbers
      17. 3.1.17. Understanding PHP error messages
        1. 3.1.17.1. Handling exceptions
    2. 3.2. PHP: A quick reference
      1. 3.2.1. Using PHP in an existing website
      2. 3.2.2. Data types in PHP
      3. 3.2.3. Doing calculations with PHP
        1. 3.2.3.1. Arithmetic operators
        2. 3.2.3.2. Determining the order of calculations
        3. 3.2.3.3. Combining calculations and assignment
      4. 3.2.4. Adding to an existing string
      5. 3.2.5. All you ever wanted to know about quotes—and more
        1. 3.2.5.1. How PHP treats variables inside strings
        2. 3.2.5.2. Using escape sequences inside double quotes
        3. 3.2.5.3. Avoiding the need to escape quotes with heredoc syntax
      6. 3.2.6. Creating arrays
        1. 3.2.6.1. Using array() to build an indexed array
        2. 3.2.6.2. Using array() to build an associative array
        3. 3.2.6.3. Using array() to create an empty array
        4. 3.2.6.4. Multidimensional arrays
        5. 3.2.6.5. Using print_r() to inspect an array
      7. 3.2.7. The truth according to PHP
        1. 3.2.7.1. Explicit Boolean values
        2. 3.2.7.2. Implicit Boolean values
        3. 3.2.7.3. Making decisions by comparing two values
        4. 3.2.7.4. Testing more than one condition
        5. 3.2.7.5. Using the switch statement for decision chains
        6. 3.2.7.6. Using the ternary operator
      8. 3.2.8. Creating loops
        1. 3.2.8.1. Loops using while and do . . . while
        2. 3.2.8.2. The versatile for loop
        3. 3.2.8.3. Looping through arrays with foreach
        4. 3.2.8.4. Breaking out of a loop
      9. 3.2.9. Modularizing code with functions
        1. 3.2.9.1. Passing values to functions
        2. 3.2.9.2. Returning values from functions
        3. 3.2.9.3. Where to locate custom-built functions
    3. 3.3. PHP quick checklist
  9. 4. Lightening Your Workload with Includes
    1. 4.1. Including code from external files
      1. 4.1.1. Introducing the PHP include commands
      2. 4.1.2. Where PHP looks for include files
        1. 4.1.2.1. PHP Solution 4-1: Moving the menu and footer to include files
      3. 4.1.3. Choosing the right filename extension for includes
        1. 4.1.3.1. PHP Solution 4-2: Testing the security of includes
        2. 4.1.3.2. PHP Solution 4-3: Automatically indicating the current page
        3. 4.1.3.3. PHP Solution 4-4: Generating a page's title from its filename
      4. 4.1.4. Creating pages with changing content
        1. 4.1.4.1. PHP Solution 4-5: Automatically updating a copyright notice
        2. 4.1.4.2. PHP Solution 4-6: Displaying a random image
        3. 4.1.4.3. PHP Solution 4-7: Adding a caption to the random image
      5. 4.1.5. Preventing errors with include files
        1. 4.1.5.1. Checking the existence of variables
        2. 4.1.5.2. Checking whether a function or class has been defined
        3. 4.1.5.3. Temporarily turning on error messages
        4. 4.1.5.4. Dealing with missing include files
        5. 4.1.5.5. PHP Solution 4-8: Redirecting when an include file can't be found
      6. 4.1.6. Choosing where to locate your include files
      7. 4.1.7. Adjusting your include_path
        1. 4.1.7.1. Editing the include_path in php.ini
        2. 4.1.7.2. Using .htaccess to change the include_path
        3. 4.1.7.3. Using set_include_path()
      8. 4.1.8. Why can't I use site-root-relative links with PHP includes?
      9. 4.1.9. Security considerations with includes
    2. 4.2. Chapter review
  10. 5. Bringing Forms to Life
    1. 5.1. How PHP gathers information from a form
      1. 5.1.1. Understanding the difference between post and get
      2. 5.1.2. Keeping safe with PHP superglobals
      3. 5.1.3. Removing unwanted backslashes from form input
        1. 5.1.3.1. PHP Solution 5-1: Using a script to eliminate magic quotes
    2. 5.2. Processing and validating user input
      1. 5.2.1. Creating a reusable script
        1. 5.2.1.1. PHP Solution 5-2: Making sure required fields aren't blank
      2. 5.2.2. Preserving user input when a form is incomplete
        1. 5.2.2.1. PHP Solution 5-3: Creating sticky form fields
      3. 5.2.3. Filtering out potential attacks
        1. 5.2.3.1. PHP Solution 5-4: Blocking emails that contain specific phrases
    3. 5.3. Sending email
      1. 5.3.1. Using additional email headers safely
        1. 5.3.1.1. PHP Solution 5-5: Adding headers and automating the reply address
        2. 5.3.1.2. PHP Solution 5-6: Building the message body and sending the mail
        3. 5.3.1.3. Troubleshooting mail()
      2. 5.3.2. Keeping spam at bay
        1. 5.3.2.1. PHP Solution 5-7: Incorporating a reCAPTCHA widget into your form
    4. 5.4. Handling multiple-choice form elements
      1. 5.4.1.
        1. 5.4.1.1. PHP Solution 5-8: Handling radio button groups
        2. 5.4.1.2. PHP Solution 5-9: Handling check boxes and check box groups
        3. 5.4.1.3. PHP Solution 5-10: Using a drop-down option menu
        4. 5.4.1.4. PHP Solution 5-11: Handling a multiple-choice list
    5. 5.5. Chapter review
  11. 6. Uploading Files
    1. 6.1. How PHP handles file uploads
      1. 6.1.1. Checking whether your server supports uploads
      2. 6.1.2. Adding a file upload field to a form
      3. 6.1.3. Understanding the $_FILES array
        1. 6.1.3.1. Inspecting the $_FILES array
      4. 6.1.4. Establishing an upload directory
        1. 6.1.4.1. Creating an upload folder for local testing on Windows
        2. 6.1.4.2. Creating an upload folder for local testing on Mac OS X
    2. 6.2. Uploading files
      1. 6.2.1. Moving the temporary file to the upload folder
        1. 6.2.1.1. PHP Solution 6-1: Creating a basic file upload script
    3. 6.3. Creating a PHP file upload class
      1. 6.3.1. Defining a PHP class
        1. 6.3.1.1. PHP Solution 6-2: Creating the basic file upload class
      2. 6.3.2. Checking upload errors
        1. 6.3.2.1. PHP Solution 6-3: Testing the error level, file size, and MIME type
      3. 6.3.3. Changing protected properties
        1. 6.3.3.1. PHP Solution 6-4: Allowing different types and sizes to be uploaded
      4. 6.3.4. Explicitly changing a data type
      5. 6.3.5. Preventing files from being overwritten
        1. 6.3.5.1. PHP Solution 6-5: Checking an uploaded file's name before saving it
    4. 6.4. Uploading multiple files
      1. 6.4.1. How the $_FILES array handles multiple files
        1. 6.4.1.1. PHP Solution 6-6: Adapting the class to handle multiple uploads
      2. 6.4.2. Using namespaces in PHP 5.3 and later
        1. 6.4.2.1. PHP Solution 6-7: Converting the class to use a namespace
    5. 6.5. Using the upload class
    6. 6.6. Points to watch with file uploads
    7. 6.7. Chapter review
  12. 7. Using PHP to Manage Files
    1. 7.1. Checking that PHP has permission to open a file
      1. 7.1.1. Configuration settings that affect file access
        1. 7.1.1.1. Accessing remote files
        2. 7.1.1.2. Configuration settings that affect local file access
      2. 7.1.2. Creating a file storage folder for local testing
    2. 7.2. Reading and writing files
      1. 7.2.1. Reading files in a single operation
        1. 7.2.1.1. PHP Solution 7-1: Getting the contents of a text file
        2. 7.2.1.2. PHP Solution 7-2: Reading a text file into an array
      2. 7.2.2. Opening and closing files for read/write operations
        1. 7.2.2.1. Reading a file with fopen()
        2. 7.2.2.2. Replacing content with fopen()
        3. 7.2.2.3. Appending content with fopen()
        4. 7.2.2.4. Writing a new file with fopen()
        5. 7.2.2.5. Combined read/write operations with fopen()
        6. 7.2.2.6. Moving the internal pointer
    3. 7.3. Exploring the file system
      1. 7.3.1. Inspecting a folder with scandir()
      2. 7.3.2. Inspecting the contents of a folder with DirectoryIterator
      3. 7.3.3. Restricting file types with the RegexIterator
        1. 7.3.3.1. PHP Solution 7-3: Building a drop-down menu of files
        2. 7.3.3.2. PHP Solution 7-4: Creating a generic file selector
    4. 7.4. Accessing remote files
      1. 7.4.1. Consuming news and other RSS feeds
      2. 7.4.2. Using SimpleXML
        1. 7.4.2.1. PHP Solution 7-5: Consuming an RSS news feed
    5. 7.5. Creating a download link
      1. 7.5.1.
        1. 7.5.1.1. PHP Solution 7-6: Prompting a user to download an image
    6. 7.6. Chapter review
  13. 8. Generating Thumbnail Images
    1. 8.1. Checking your server's capabilities
    2. 8.2. Manipulating images dynamically
      1. 8.2.1. Making a smaller copy of an image
        1. 8.2.1.1. Getting ready
        2. 8.2.1.2. Building the Ps2_Thumbnail class
        3. 8.2.1.3. PHP Solution 8-1: Getting the image details
        4. 8.2.1.4. PHP Solution 8-2: Creating the setter methods
        5. 8.2.1.5. PHP Solution 8-3: Final preparations for generating the thumbnail
        6. 8.2.1.6. PHP Solution 8-4: Generating the thumbnail image
    3. 8.3. Resizing an image automatically on upload
      1. 8.3.1. Extending a class
        1. 8.3.1.1. PHP Solution 8-5: Creating the Ps2_ThumbnailUpload class
      2. 8.3.2. Using the Ps2_ThumbnailUpload class
    4. 8.4. Chapter summary
  14. 9. Pages That Remember: Simple Login and Multipage Forms
    1. 9.1. What sessions are and how they work
      1. 9.1.1. Creating PHP sessions
      2. 9.1.2. Creating and destroying session variables
      3. 9.1.3. Destroying a session
      4. 9.1.4. Regenerating the session ID
      5. 9.1.5. The "Headers already sent" error
    2. 9.2. Using sessions to restrict access
      1. 9.2.1.
        1. 9.2.1.1. PHP Solution 9-1: A simple session example
        2. 9.2.1.2. PHP Solution 9-2: Buffering the output with ob_start()
      2. 9.2.2. Using file-based authentication
        1. 9.2.2.1. PHP Solution 9-3: Building the login page
        2. 9.2.2.2. PHP Solution 9-4: Restricting access to a page with a session
        3. 9.2.2.3. PHP Solution 9-5: Creating a reusable logout button
      3. 9.2.3. Making passwords more secure
        1. 9.2.3.1. PHP Solution 9-6: Creating a password strength checker
        2. 9.2.3.2. PHP Solution 9-7: Creating a file-based user registration system
        3. 9.2.3.3. PHP Solution 9-8: Using an encrypted login
    3. 9.3. Setting a time limit on sessions
      1. 9.3.1.
        1. 9.3.1.1. PHP Solution 9-9: Ending a session after a period of inactivity
    4. 9.4. Passing information through multipage forms
      1. 9.4.1.
        1. 9.4.1.1. PHP Solution 9-10: Using sessions for a multipage form
    5. 9.5. Chapter review
  15. 10. Getting Started with MySQL
    1. 10.1. Why MySQL?
      1. 10.1.1. Which version?
    2. 10.2. How a database stores information
      1. 10.2.1. How primary keys work
      2. 10.2.2. Linking tables with primary and foreign keys
      3. 10.2.3. Breaking down information into small chunks
      4. 10.2.4. Checkpoints for good database design
    3. 10.3. Using MySQL with a graphical interface
      1. 10.3.1. Launching phpMyAdmin
    4. 10.4. Setting up the phpsols database
      1. 10.4.1. MySQL naming rules
        1. 10.4.1.1. Case sensitivity of names
      2. 10.4.2. Using phpMyAdmin to create a new database
      3. 10.4.3. Creating database-specific user accounts
        1. 10.4.3.1. Granting user privileges
      4. 10.4.4. Creating a database table
        1. 10.4.4.1. Defining the images table
      5. 10.4.5. Inserting records into a table
        1. 10.4.5.1. Using phpMyAdmin to insert records manually
        2. 10.4.5.2. Loading the images records from a SQL file
      6. 10.4.6. Creating a SQL file for backup and data transfer
    5. 10.5. Choosing the right data type in MySQL
      1. 10.5.1. Storing text
      2. 10.5.2. Storing numbers
      3. 10.5.3. Storing dates and times
      4. 10.5.4. Storing predefined lists
      5. 10.5.5. Storing binary data
    6. 10.6. Chapter review
  16. 11. Connecting to MySQL with PHP and SQL
    1. 11.1. Checking your remote server setup
    2. 11.2. How PHP communicates with MySQL
      1. 11.2.1. Connecting with the MySQL Improved extension
      2. 11.2.2. Connecting with PDO
        1. 11.2.2.1. PHP Solution 11-1: Making a reusable database connector
      3. 11.2.3. Finding the number of results from a query
        1. 11.2.3.1. PHP Solution 11-2: Counting records in a result set (MySQLi)
        2. 11.2.3.2. PHP Solution 11-3: Counting records in a result set (PDO)
      4. 11.2.4. Displaying the results of a query
        1. 11.2.4.1. PHP Solution 11-4: Displaying the images table using MySQLi
        2. 11.2.4.2. PHP Solution 11-5: Displaying the images table using PDO
      5. 11.2.5. MySQL connection crib sheet
    3. 11.3. Using SQL to interact with a database
      1. 11.3.1. Writing SQL queries
        1. 11.3.1.1. SQL is case-insensitive
        2. 11.3.1.2. Whitespace is ignored
        3. 11.3.1.3. Strings must be quoted
        4. 11.3.1.4. Handling numbers
      2. 11.3.2. Refining the data retrieved by a SELECT query
        1. 11.3.2.1. Selecting specific columns
        2. 11.3.2.2. Changing the order of results
        3. 11.3.2.3. Searching for specific values
        4. 11.3.2.4. Searching for text with wildcard characters
      3. 11.3.3. Understanding the danger of SQL injection
        1. 11.3.3.1. PHP Solution 11-6: Inserting an integer from user input into a query
        2. 11.3.3.2. PHP Solution 11-7: Inserting a string with real_escape_string()
        3. 11.3.3.3. Embedding variables in MySQLi prepared statements
        4. 11.3.3.4. PHP Solution 11-8: Using a MySQLi prepared statement in a search
        5. 11.3.3.5. Embedding variables in PDO prepared statements
        6. 11.3.3.6. PHP Solution 11-9: Using a PDO prepared statement in a search
        7. 11.3.3.7. PHP Solution 11-10: Changing column options through user input
    4. 11.4. Chapter review
  17. 12. Creating a Dynamic Online Gallery
    1. 12.1. Why not store images in a database?
    2. 12.2. Planning the gallery
    3. 12.3. Converting the gallery elements to PHP
      1. 12.3.1.
        1. 12.3.1.1. PHP Solution 12-1: Displaying the first image
    4. 12.4. Building the dynamic elements
      1. 12.4.1. Passing information through a query string
        1. 12.4.1.1. PHP Solution 12-2: Activating the thumbnails
      2. 12.4.2. Creating a multicolumn table
        1. 12.4.2.1. PHP Solution 12-3: Looping horizontally and vertically
      3. 12.4.3. Paging through a long set of records
        1. 12.4.3.1. Selecting a subset of records
        2. 12.4.3.2. PHP Solution 12-4: Displaying a subset of records
        3. 12.4.3.3. Navigating through subsets of records
        4. 12.4.3.4. PHP Solution 12-5: Creating the navigation links
    5. 12.5. Chapter review
  18. 13. Managing Content
    1. 13.1. Setting up a content management system
      1. 13.1.1. Creating the blog database table
      2. 13.1.2. Creating the basic insert and update form
      3. 13.1.3. Inserting new records
        1. 13.1.3.1. PHP Solution 13-1: Inserting a new record with MySQLi
        2. 13.1.3.2. PHP Solution 13-2: Inserting a new record with PDO
      4. 13.1.4. Linking to the update and delete pages
        1. 13.1.4.1. PHP Solution 13-3: Creating the links to the update and delete pages
      5. 13.1.5. Updating records
        1. 13.1.5.1. PHP Solution 13-4: Updating a record with MySQLi
        2. 13.1.5.2. PHP Solution 13-5: Updating a record with PDO
      6. 13.1.6. Deleting records
    2. 13.2. Reviewing the four essential SQL commands
      1. 13.2.1. SELECT
      2. 13.2.2. INSERT
      3. 13.2.3. UPDATE
      4. 13.2.4. DELETE
    3. 13.3. Security and error messages
    4. 13.4. Chapter review
  19. 14. Formatting Text and Dates
    1. 14.1. Displaying a text extract
      1. 14.1.1. Extracting a fixed number of characters
        1. 14.1.1.1. Using the PHP substr() function
        2. 14.1.1.2. Using the MySQL LEFT() function
      2. 14.1.2. Ending an extract on a complete word
      3. 14.1.3. Extracting the first paragraph
        1. 14.1.3.1. Displaying paragraphs
      4. 14.1.4. Extracting complete sentences
        1. 14.1.4.1. PHP Solution 14-1: Displaying the first two sentences of an article
    2. 14.2. Let's make a date
      1. 14.2.1. How MySQL handles dates
        1. 14.2.1.1. Formatting dates in a SELECT query with DATE_FORMAT()
        2. 14.2.1.2. PHP Solution 14-2: Formatting a MySQL date or timestamp
        3. 14.2.1.3. Adding to and subtracting from dates
        4. 14.2.1.4. PHP Solution 14-3: Displaying items updated within the past week
      2. 14.2.2. Inserting dates into MySQL
        1. 14.2.2.1. PHP Solution 14-4: Validating and formatting dates for MySQL input
      3. 14.2.3. Working with dates in PHP
        1. 14.2.3.1. Setting the default time zone
        2. 14.2.3.2. Creating a DateTime object
        3. 14.2.3.3. Formatting dates in PHP
        4. 14.2.3.4. Creating a DateTime object from a custom format
        5. 14.2.3.5. Choosing between date() and the DateTime class
        6. 14.2.3.6. Using the DateTimeZone class
        7. 14.2.3.7. Adding and subtracting set periods with the DateInterval class
        8. 14.2.3.8. Finding the difference between two dates with the diff() method
        9. 14.2.3.9. Calculating recurring dates with the DatePeriod class
    3. 14.3. Chapter review
  20. 15. Pulling Data from Multiple Tables
    1. 15.1. Understanding table relationships
    2. 15.2. Linking an image to an article
      1. 15.2.1. Altering the structure of an existing table
        1. 15.2.1.1. PHP Solution 15-1: Adding an extra column to a table
      2. 15.2.2. Inserting a foreign key in a table
        1. 15.2.2.1. PHP Solution 15-2: Adding the image foreign key
      3. 15.2.3. Selecting records from multiple tables
        1. 15.2.3.1. PHP Solution 15-3: Building the details page
      4. 15.2.4. Finding records that don't have a matching foreign key
      5. 15.2.5. Creating an intelligent link
        1. 15.2.5.1. PHP Solution 15-4: Returning to the same point in a navigation system
    3. 15.3. Chapter review
  21. 16. Managing Multiple Database Tables
    1. 16.1. Maintaining referential integrity
      1. 16.1.1.
        1. 16.1.1.1. PHP Solution 16-1: Checking whether InnoDB is supported
    2. 16.2. Inserting records into multiple tables
      1. 16.2.1. Creating a cross-reference table
        1. 16.2.1.1. Setting up the categories and cross-reference tables
      2. 16.2.2. Getting the filename of an uploaded image
        1. 16.2.2.1. PHP Solution 16-2: Improving the Ps2_Upload class
      3. 16.2.3. Adapting the insert form to deal with multiple tables
        1. 16.2.3.1. PHP Solution 16-3: Adding the category and image input fields
        2. 16.2.3.2. PHP Solution 16-4: Inserting data into multiple tables
    3. 16.3. Updating and deleting records in multiple tables
      1. 16.3.1. Updating records in a cross-reference table
        1. 16.3.1.1. PHP Solution 16-5: Adding categories to the update form
      2. 16.3.2. Preserving referential integrity on deletion
        1. 16.3.2.1. PHP Solution 16-6: Converting tables to the InnoDB storage engine
        2. 16.3.2.2. PHP Solution 16-7: Setting up foreign key constraints
      3. 16.3.3. Creating delete scripts with foreign key constraints
      4. 16.3.4. Creating delete scripts without foreign key constraints
    4. 16.4. Chapter review
  22. 17. Authenticating Users with a Database
    1. 17.1. Choosing an encryption method
    2. 17.2. Using one-way encryption
      1. 17.2.1. Creating a table to store users' details
      2. 17.2.2. Registering new users in the database
        1. 17.2.2.1. PHP Solution 17-1: Creating a user registration form
        2. 17.2.2.2. PHP Solution 17-2: Authenticating a user's credentials with a database
    3. 17.3. Using two-way encryption
      1. 17.3.1. Creating the table to store users' details
      2. 17.3.2. Registering new users
      3. 17.3.3. User authentication with two-way encryption
      4. 17.3.4. Decrypting a password
    4. 17.4. Updating user details
    5. 17.5. Where next?