PHP & MySQL: The Missing Manual
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
If you can build websites with CSS and JavaScript, this book takes you to the next level—creating dynamic, database-driven websites with PHP and MySQL. Learn how to build a database, manage your content, and interact with users through queries and web forms. With step-by-step tutorials, real-world examples, and jargon-free explanations, you’ll soon discover the power of server-side programming.
The important stuff you need to know:
- Get a running start. Write PHP scripts and create a web form right away.
- Learn the language. Get up to speed on PHP and SQL syntax quickly.
- Build a database. Use MySQL to store user information and other data.
- Make it dynamic. Create pages that change with each new viewing.
- Be ready for mistakes. Plan error messages to help direct users.
- Manage your content. Use the file system to access user data, including images and other binary files.
- Control operations. Create an administrative interface to oversee your site.
Publisher resources
Table of contents
- A Note Regarding Supplemental Files
- The Missing Credits
- About the Author
- About the Creative Team
- Acknowledgments
- The Missing Manual Series
- What Is PHP?
- PHP Is All About the Web
- JavaScript Is Loose, PHP Is…Less So
- PHP Is Interpreted
- Macintosh and Windows
- FTP: It’s Critical
- About the Outline
- Missing CD
- Registration
- Feedback
- Errata
- 1. PHP: What, Why, and Where?
- Gathering Your Tools
- PHP on the PC
- PHP on the Mac
- Get Out Your Text Editor
- Start with an HTML Page
- Write a PHP Script
- Variables Vary
- Get Information from a Web Form
- Access Request Parameters Directly
- Create Your Own Variables
- Combining Text
- Searching Within Text
- Changing Text
- Trimming and Replacing Text
- Remove Extra White Space with trim()
- Replace Characters in Text with str_replace()
- Arrays Can Hold Multiple Values
- Working with $_REQUEST as an Array
- What Is a Database?
- Databases Are Persistent
- Databases Are All About Structure
- (Good) Databases Are Relational
- MySQL on Windows
- MySQL on Mac OS X
- Running Your First SQL Query
- Logging In to Your Web Server’s Database
- USE a Database
- Making Tables with CREATE
- Deleting Tables with DROP
- INSERT a Few Rows
- SELECT for the Grand Finale
- 4. Connecting PHP to MySQL
- Writing a Simple PHP Connection Script
- Connecting to a MySQL Database
- Selecting the Database to USE
- SHOW Your Database’s Tables
- Handling Errors By Seeing If Your Results are Not
- Printing Out Your SQL Results
- Replacing Hand-Typed Values with Variables
- Abstracting Important Values into a Separate File
- Variables Vary, But Constants Stay Constant
- Creating an HTML Form with a Big Empty Box
- Connecting to Your Database (Again)
- Running Your User’s SQL Query (Again)
- Entering Your First Web-Based Query
- Handling Queries That Don’t SELECT Information
- Dealing with Humans
- Avoid Changing User Input Whenever Possible
- String Matching, Double-Time
- A Simple String Searcher
- Search for One String…Or Another
- Get into Position
- Ditching trim and strtoupper
- Searching for Sets of Characters
- Regular Expressions: To Infinity and Beyond
- Revisiting a User’s Information
- Planning Your Database Tables
- Good Database Tables Have id Columns
- Auto-Increment Is Your Friend
- IDs and Primary Keys are Good Bedfellows
- Building Your SQL Query
- Inserting a User
- A First Pass at Confirmation
- Users Are Users, Not Programmers
- Mocking Up a User Profile Page
- Changing a Table’s Structure with ALTER
- Building Your Script: First Pass
- SELECT a User From Your Database
- Pulling Values From a SQL Query Result
- Getting a User ID into show_user.php
- Updating Your User Signup Form
- Updating Your User Creation Script
- Rounding Things Out with Regular Expressions (Again)
- 7. When Things Go Wrong (and They Will)
- Planning Your Error Pages
- What Should Users See?
- Tell Your Users that a Problem has Occurred
- Use the Appropriate Tone for Your Error Message
- Creating a PHP Error Page
- Testing out Your Faulty Solution
- Expect the Unexpected
- Welcome to Security and Phishing
- Phishing and Subtle Redirection
- The Dangers of Request Parameters
- Turn on PHP Error Reporting
- Set Error Reporting Globally
- Turn Off Error Reporting When You Go to Production
- Updating Your Script to Use show_error.php
- Simplify and Abstract
- redirect is Path-Insensitive
- Images Are Just Files
- HTML Forms Can Set the Stage
- Uploading a User’s Image to Your Server
- Setting Up Some Helper Variables
- Did the File Upload with Any Errors?
- Is this Really an Uploaded File?
- Is the Uploaded File Really an Image?
- Moving the File to a Permanent Location
- Creating a New Database Column
- Inserting the Image Path into Your Table
- Checking Your Work
- SELECT the Image and Display It
- Converting File System Paths to URLs
- Displaying Your User’s Image: Take Two
- A Few Quick Revisions to app_config.php
- Storing Different Objects in Different Tables
- Inserting a Raw Image into a Table
- getimagesize Doesn’t Return a File Size
- file_get_contents Does What You Think It Does
- INSERT the Image
- Printing a String to a Variable
- Getting the Correct ID Before Redirecting
- Inserting an Image, then Inserting a User
- Joining Tables with WHERE
- Connect Your Tables Through Common Columns
- Alias Your Tables (and Columns)
- Displaying an Image
- Game Plan Your Script
- Get the Image ID
- Build and Run a Select Query
- Get the Results, Get the Image, and Deal with Potential Errors
- Tell the Browser What’s Coming
- Send the Image Data
- All You Need is an Image ID
- A Script Can Be an Image src
- OK, If You Insist on an Answer…
- Some Things Never Change
- (User Interface) Brevity is Still the Soul of Wit
- Wish Lists are Good, Too
- SELECTing What You Need (Now)
- Building a Simple Admin Page
- Iterating Over Your Array
- Surveying the Individual Components
- Putting It All Together
- Deleting Users Shouldn’t Be Magical
- Start with a Little Javascript
- Finish with a Change in Linking
- redirect Has Some Limitations
- JavaScript alert Redux
- An All-Javascript Approach
- Your PHP Controls Your Output
- Building a New Utility Function for Display
- Duplicate Code is a Problem Waiting to Happen
- View and Display Code Belongs Together
- Calling Repeated Code from a View Script
- Flexible Functions are Better Functions
- Use Default Argument Values in Display_Messages
- Outputting a Standard Header with Heredoc
- Updating Your Script(S) to Use Display_Head
- 11. Authentication and Authorization
- Start with Basic Authentication
- Basic Authentication Using HTTP Headers
- Basic Authentication is…Pretty Basic
- The Worst Authentication Ever
- Get Your User’s Credentials
- Cancel is Not a Valid Means of Authentication
- Get Your User’s Credentials (Really!)
- Another Utility Script: authorize.php
- Updating the users Table
- Deal with Newly Invalid Data
- You Need to Get an Initial Username and Password
- Inserting the User’s Username and Password
- Connect authorize.php to Your users Table
- Encrypt Text with the crypt Function
- crypt is One-Way Encryption
- Encryption Uses Salt
- Going Beyond Basic Authentication
- Starting with a Landing Page
- Taking Control of User Sign-ins
- From HTTP Authentication to Cookies
- What is a Cookie?
- Create and Retrieve Cookies
- Is the User is Already Signed In?
- Is the User Trying to Sign In?
- Displaying the page
- Redirecting as Needed
- Logging the User In
- Blank Pages and Expiring Cookies
- Errors Aren’t Always Interruptive
- An Option for Repeat Attempts
- Putting a Menu Into Place
- From HTML to Scripts
- Any HTML File Can Be Converted to PHP
- Challenge: Be Self-Referential with User Creation
- Modeling Groups in Your Database
- Adding a Groups Table
- The Many-to-Many Relationship
- One-to-One, One-to-Many, Many-to-Many
- Joins are Best Done with IDs
- Using a Join Table to Connect Users with Groups
- authorize.php Needs a Function
- Taking in a List of Groups
- Iterating Over Each Group
- Allow, Deny, Redirect
- Sessions are Server-Side
- Sessions Must Be Started
- From $_COOKIE to $_SESSION
- Sessions Must be Restarted, Too
- $_REQUEST Doesn’t Include $_SESSION
- Menu, Anyone?
- And Then Sign Out…
Product information
- Title: PHP & MySQL: The Missing Manual
- Author(s): Brett McLaughlin
- Release date: November 2011
- Publisher(s): O’Reilly Media, Inc.
- ISBN: 9780596515867
You might also like
Check it out now on O’Reilly
Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day.
PHP & MySQL: The Missing Manual, 2nd Edition
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
If you can build websites with CSS and JavaScript, this book takes you to the next level—creating dynamic, database-driven websites with PHP and MySQL. Learn how to build a database, manage your content, and interact with users. With step-by-step tutorials, this completely revised edition gets you started with expanded coverage of the basics and takes you deeper into the world of server-side programming.
The important stuff you need to know:
- Get up to speed quickly. Learn how to install PHP and MySQL, and get them running on both your computer and a remote server.
- Gain new techniques. Take advantage of the all-new chapter on integrating PHP with HTML web pages.
- Manage your content. Use the file system to access user data, including images and other binary files.
- Make it dynamic. Create pages that change with each new viewing.
- Build a good database. Use MySQL to store user information and other data.
- Keep your site working. Master the tools for fixing things that go wrong.
- Control operations. Create an administrative interface to oversee your site.
- Start with Basic Authentication
- What Should Users See?
- Planning Your Error Pages
- Writing a Simple PHP Connection Script
- Gathering Your Tools