Contents

About the Authors

About the Technical Reviewer

Acknowledgments

Introduction

imagesPart I: PHP/MySQL Basics

imageChapter 1: Setting Up a PHP Development Environment

Why You Need Apache, MySQL, and PHP

How PHP Works

Apache and What It Does

Storing Info with MySQL

Installing PHP, Apache, and MySQL

Installing XAMPP

Open the XAMPP Control Panel

What If Apache Isn’t Running?

Verify That Apache and PHP Are Running

Choosing a PHP Editor

Creating Your First PHP File

Running Your First PHP Script

Summary

imageChapter 2: Understanding PHP: Language Basics

Embedding PHP Scripts

Using echo

What Is a Variable?

Displaying PHP Errors

Creating an HTML5 Page with PHP

Including a Simple Page Template

Returning Values

Including the Template

Commenting Your Code

Avoiding Naming Conflicts

Page Views

Making a Dynamic Site Navigation

Passing Information with PHP

Accessing URL Variables

Using isset( ) to Test If a Variable Is Set

$_GET, a Superglobal Array

Including Page Views Dynamically

Concatenation

Strict Naming Convention

Displaying a Default Page

Validating Your HTML

Styling the Site with CSS

Declaring a Page_Data Class

Classes Make Objects

Highlighting Current Navigation Item with a Dynamic Style Rule

Summary

imageChapter 3: Form Management

What Are Forms?

Setting Up a New PHP Project

Seeing for Yourself

Creating a Dynamic Navigation

Creating Page Views for the Form

Spending Your Time Wisely: Conventions and Reuse

A Super-Simple Search Form

Trying Your Search Form

Forms Encode URL Variables

Named PHP Functions

The Basic Syntax for Functions

Using Function Arguments for Increased Flexibility

Creating a Form for the Quiz

Showing the Quiz Form

Evaluating the Quiz Response

Curly’s Law: Do One Thing

Meaningful Names

Styling Forms

Exercises

Summary

imageChapter 4: Building a Dynamic Image Gallery with Image Upload

Setting Up a Dynamic Site

Prerequisites: A Folder with Some Images

Creating a Navigation

Creating Two Dummy Page View Files

Creating the Index File

Time to Test

Adding Two Style Sheets to One Page

Staying DRY

Improving the Page_Data Class with a Method

Is It a Function or a Method?

What Is $this?

Using the New Method

You Can Only Use Methods That Are Declared

Preparing a Function for Displaying Images

Iteration

Using a DirectoryIterator to Find Files in a Folder

Showing All Images

Creating a Form View

Showing a Form for Uploading Images

$_FILES

Uploading Files with PHP

Planning an Uploader Class

Using the Uploader Class

The Single Responsibility Principle

Summary

imageChapter 5: Spicing Up Your Image Gallery with JavaScript and CSS

Client-Side vs. Server-Side Programming

Coding a Lightbox Gallery

Embedding an External JavaScript File

Preparing the Page_Data Class for JavaScript Files

Preparing the Page Template for JavaScript Files

Writing and Running an External JavaScript File

Using window.console.log( )

JavaScript Arrays

Simple Progressive Enhancement

Creating Markup for the Overlay and Big Image

Showing the Overlay

Hiding the Overlay and Resize Thumbnails

Showing a Big Image

Hiding the Big Image

Using a CSS Animation

Coding Challenge

Summary

imageChapter 6: Working with Databases

The Basics of MySQL Data Storage

Manipulating Data with SQL

Developing a Database for the Poll

Creating a Database Using CREATE

The INSERT Statement

The SELECT Statement

The UPDATE Statement

Coding a Database-Driven Site Poll

Separating Concerns with MVC

Creating the Poll Project

Making a Poll Controller

Making a Poll Model

Making a Poll View

Hooking Up Poll View with Poll Model

Coding Is Like Playing the Blues

Connecting to MySQL from PHP

Using Constructor Arguments

Sharing the Database Connection with the Poll Model

Retrieving Data with a PDOStatement

PDO and PDOStatement Objects

Showing a Poll Form

Updating a Database Table According to Form Input

Summary

imagesPart II: A Blogging System

imageChapter 7: Building the Entry Manager

Creating the blog_entry Database Table

Planning the PHP Scripts

Creating the Blog Site

Creating the Entry Manager Navigation

Loading Admin Module Controllers

Creating the Entry Input Form

Styling the Editor

Connecting to the Database

Using Design Patterns

Writing the Entry_Table Class

Processing Form Input and Saving the Entry

Summary

imageChapter 8: Showing Blog Entries

Creating a Public Blog Front Page

Creating a Blog Controller

Getting Data for All Blog Entries

Preparing a View for All Blog Entries

Hooking Up View and Model

Responding to User Requests

Getting Entry Data

Creating a Blog View

Displaying an Entry

Code Smell: Duplicate Code

Using the Private Access Modifier

Summary

imageChapter 9: Deleting and Updating Entries

Creating a Model for Administrative Links

Displaying Administrative Links

Populating Your Form with the Entry to Be Edited

Handling Entry Deletion

Deleting Entries from the Database

Responding to Delete Requests

Preparing a Model to Update Entries in the Database

Controller: Should I Insert or Update?

Communicating Changes

Insisting on a Title

Improving Editor Usability with Progressive Enhancement

Embedding Your External JavaScript

Showing a Warning If Title Is Empty

Other Usability Flaws

A Coding Challenge: Fix a Usability Flaw

Summary

imageChapter 10: Improving Your Blog with User Comments and Search

Building and Displaying the Comment Entry Form

A Combined View

Creating a Comment Table in the Database

Using a Foreign Key

Building a Comment_Table Class

Staying DRY with Inheritance

Is-a Relationships

Using Inheritance in Your Code

Inserting New Comments into the Database

Retrieving All Comments for a Given Entry

Inserting a Comment Through the Comment Form

Practice Makes Perfect

Searching for Entries

The Search View

Responding to a User Search

The Search Model

A Search Result View

Loading a Search Result View from the Controller

Exercise: Improving Search

Summary

imageChapter 11: Adding Images to Blog Entries

Problem: Cannot Delete an Entry with Comments

Understanding Foreign Key Constraints

Deleting Comments Before Blog Entry

Improving Usability with WYSIWYG

Integrating TinyMCE

Creating an Image Manager

Showing a Form for Uploading Images

A Quick Refresher on the $_FILES Superglobal Array

Uploading an Image

What Could Possibly Go Wrong?

Displaying Images

Deleting Images

Using an Image in a Blog Entry

Improving Editor Usability

Summary

imageChapter 12: Password Protection

Creating an admin_table in the Database

Encrypting Passwords with MD5

One-Way Encryption

Sufficient Security

Adding Administrators in the Database

Building an HTML Form

Saving New Administrators in the Database

Planning Login

Creating a Login Form

Hiding Controls from Unauthorized Users

Logging In a User

Logging Users Out

Allowing Authorized Users Only

Exercises

Summary

imageChapter 13: Going Public with Your Blog

Web Host Requirements

Exporting and Importing Your Database

Preparing Your PHP Files for Upload

Uploading Files with FileZilla FTP

Summary

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.187.113