Head First PHP & MySQL: A Brain-friendly Guide by Lynn BeighleyHead First PHP & MySQL: A Brain-friendly Guide by Lynn Beighley

Head First PHP & MySQL: A Brain-friendly Guide

byLynn Beighley, Michael Morrison

Paperback | January 1, 2009

Pricing and Purchase Info

$43.23 online 
$58.50 list price save 26%
Earn 216 plum® points

Prices and offers may vary in store


In stock online

Ships free on orders over $25

Not available in stores


If you're ready to create web pages more complex than those you can build with HTML and CSS, Head First PHP & MySQL is the ultimate learning guide to building dynamic, database-driven websites using PHP and MySQL. Packed with real-world examples, this book teaches you all the essentials of server-side programming, from the fundamentals of PHP and MySQL coding to advanced topics such as form validation, session IDs, cookies, database queries and joins, file I/O operations, content management, and more.

Head First PHP & MySQL offers the same visually rich format that's turned every title in the Head First series into a bestseller, with plenty of exercises, quizzes, puzzles, and other interactive features to help you retain what you've learned.

  • Use PHP to transform static HTML pages into dynamic web sites
  • Create and populate your own MySQL database tables, and work with data stored in files
  • Perform sophisticated MySQL queries with joins, and refine your results with LIMIT and ORDER BY
  • Use cookies and sessions to track visitors' login information and personalize the site for users
  • Protect your data from SQL injection attacks
  • Use regular expressions to validate information on forms
  • Dynamically display text based on session info and create images on the fly
  • Pull syndicated data from other sites using PHP and XML
Throughout the book, you'll build sophisticated examples -- including a mailing list, a job board, and an online dating site -- to help you learn how to harness the power of PHP and MySQL in a variety of contexts. If you're ready to build a truly dynamic website, Head First PHP & MySQL is the ideal way to get going.
Lynn Beighley is a fiction writer stuck in a technical book writer's body. Upon discovering that technical book writing actually paid real money, she learned to accept and enjoy it. After going back to school to get a Masters in Computer Science, she worked for the acronyms NRL and LANL. Then she discovered Flash, and wrote her first b...
Title:Head First PHP & MySQL: A Brain-friendly GuideFormat:PaperbackDimensions:814 pages, 9.25 × 8 × 1.8 inPublished:January 1, 2009Publisher:O'Reilly MediaLanguage:English

The following ISBNs are associated with this title:

ISBN - 10:0596006306

ISBN - 13:9780596006303

Look for similar items by category:


Table of Contents

; Advance Praise for Head First PHP & MySQL; Praise for Head First HTML with CSS & XHTML; Praise for Head First JavaScript; Author(s) of Head First PHP & MySQL; How to Use This Book: Intro; Who is this book for?; Who should probably back away from this book?; We know what you''re thinking; We know what your brain is thinking; Metacognition: thinking about thinking; Here''s what WE did:; Here''s what YOU can do to bend your brain into submission; Read Me; The technical review team; Acknowledgments; Safari Books Online; Chapter 1: Add Life to your Static Pages: It''s Alive; 1.1 HTML is static and boring; 1.2 PHP brings web pages to life; 1.3 Dogs in space; 1.4 A form helps Owen get the whole story; 1.5 Forms are made of HTML; 1.6 The HTML form has problems; 1.7 HTML acts on the CLIENT; 1.8 PHP acts on the SERVER; 1.9 PHP scripts run on the server; 1.10 Use PHP to access the form data; 1.11 PHP scripts must live on a server!; 1.12 Get your PHP scripts to the server; 1.13 The server turns PHP into HTML; 1.14 Deconstructing Owen''s PHP script; 1.15 A few PHP rules to live code by; 1.16 Finding the perfect variable name; 1.17 Variables are for storing script data; 1.18 $-POST is a special variable that holds form data; 1.19 $-POST transports form data to your script; 1.20 Creating the email message body with PHP; 1.21 Even plain text can be formatted... a little; 1.22 Newlines need double-quoted strings; 1.23 Assemble an email message for Owen; 1.24 Variables store the email pieces and parts; 1.25 Sending an email message with PHP; 1.26 Owen starts getting emails; 1.27 Owen starts losing emails; 1.28 Your PHP & MySQL Toolbox; Chapter 2: Connecting to MySQL: How it fits together; 2.1 Owen''s PHP form works well. Too well...; 2.2 MySQL excels at storing data; 2.3 Owen needs a MySQL database; 2.4 Create a MySQL database and table; 2.5 The INSERT statement in action; 2.6 Use SELECT to get table data; 2.7 Let PHP handle the tedious SQL stuff; 2.8 PHP lets data drive Owen''s web form; 2.9 Connect to your database from PHP; 2.10 Insert data with a PHP script; 2.11 Use PHP functions to talk to the database; 2.12 Get connected with mysqli_connect(); 2.13 Build the INSERT query in PHP; 2.14 Query the MySQL database with PHP; 2.15 Close your connection with mysqli-close(); 2.16 $-POST provides the form data; 2.17 Owen needs help sifting through his data; 2.18 Owen''s on his way to finding Fang; Chapter 3: Create and Populate a Database: Creating your own data; 3.1 The Elvis store is open for business; 3.2 Elmer needs an application; 3.3 Visualize Elmer''s application design; 3.4 It all starts with a table; 3.5 Make contact with the MySQL server; 3.6 Create a database for Elmer''s emails; 3.7 Create a table inside the database; 3.8 We need to define our data; 3.9 Take a meeting with some MySQL data types; 3.10 Create your table with a query; 3.11 Getting the cart table in front of the horse database; 3.12 USE the database before you use it; 3.13 DESCRIBE reveals the structure of tables; 3.14 Elmer''s ready to store data; 3.15 Create the Add Email script; 3.16 The other side of Elmer''s application; 3.17 The nuts and bolts of the Send Email script; 3.18 First things first, grab the data; 3.19 mysqli_fetch_array() fetches query results; 3.20 Looping for a WHILE; 3.21 Looping through data with while; 3.22 You''ve got mail...from Elmer!; 3.23 Sometimes people want out; 3.24 Removing data with DELETE; 3.25 Use WHERE to DELETE specific data; 3.26 Minimize the risk of accidental deletions; 3.27 MakeMeElvis.com is a web application; 3.28 Your PHP & MySQL Toolbox; Chapter 4: Realistic and Practical Applications: Your Application on the Web; 4.1 Elmer has some irritated customers; 4.2 Protecting Elmer from... Elmer; 4.3 Demand good form data; 4.4 The logic behind Send Email validation; 4.5 Your code can make decisions with IF; 4.6 Testing for truth; 4.7 IF checks for more than just equality; 4.8 The logic behind Send Email validation; 4.9 PHP functions for verifying variables; 4.10 Test multiple conditions with AND and OR; 4.11 Form users need feedback; 4.12 Ease in and out of PHP as needed; 4.13 Use a flag to avoid duplicate code; 4.14 Code the HTML form only once; 4.15 A form that references itself; 4.16 Point the form action at the script; 4.17 Check to see if the form has been submitted; 4.18 Some users are still disgruntled; 4.19 Table rows should be uniquely identifiable; 4.20 Primary keys enforce uniqueness; 4.21 The five rules of primary keys:; 4.22 From checkboxes to customer IDs; 4.23 Loop through an array with foreach; 4.24 Your PHP & MySQL Toolbox; Chapter 5: Working with Data Stored in Files: When a database just isn''t enough; 5.1 Virtual guitarists like to compete; 5.2 The proof is in the rockin'' picture; 5.3 The application needs to store images; 5.4 Planning for image file uploads in Guitar Wars; 5.5 The high score database must be ALTERed; 5.6 How do we get an image from the user?; 5.7 Insert the image filename into the database; 5.8 Find out the name of the uploaded file; 5.9 Where did the uploaded file go?; 5.10 Create a home for uploaded image files; 5.11 Shared data has to be shared; 5.12 Shared script data is required; 5.13 Think of require_once as "insert"; 5.14 Timing Order is everything with high scores; 5.15 Honoring the top Guitar Warrior; 5.16 Format the top score with HTML and CSS; 5.17 Only small images allowed; 5.18 File validation makes the app more robust; 5.19 Plan for an Admin page; 5.20 Generate score removal links on the Admin page; 5.21 Scripts can communicate with each other; 5.22 Of GETs and POSTs; 5.23 GET, POST, and high score removal; 5.24 Isolate the high score for deletion; 5.25 Control how much you delete with LIMIT; 5.26 Your PHP & MySQL Toolbox; Chapter 6: Securing your Application: Assume they''re all out to get you; 6.1 The day the music died; 6.2 Where did the high scores go?; 6.3 Securing the teeming hordes; 6.4 Protecting the Guitar Wars Admin page; 6.5 HTTP authentication requires headers; 6.6 Take control of headers with PHP; 6.7 Authenticating with headers; 6.8 Create an Authorize script; 6.9 Guitar Wars Episode II : Attack of the High Score Clones; 6.10 Subtraction by addition; 6.11 Security requires humans; 6.12 Plan for moderation in Guitar Wars; 6.13 Make room for approvals with ALTER; 6.14 Unapproved scores aren''t worthy; 6.15 The million-point hack; 6.16 Everything in moderation... ?; 6.17 How exactly did she do it?; 6.18 Tricking MySQL with comments; 6.19 The Add Score form was SQL injected; 6.20 Protect your data from SQL injections; 6.21 A safer INSERT (with parameters); 6.22 Form validation can never be too smart; 6.23 Cease fire!; 6.24 Your PHP & MySQL Toolbox; Chapter 7: building personalized web apps: Remember me?; 7.1 They say opposites attract; 7.2 Mismatch is all about personal data; 7.3 Mismatch needs user log-ins; 7.4 Come up with a user log-in gameplan; 7.5 Prepping the database for log-ins; 7.6 Constructing a log-in user interface; 7.7 Encrypt passwords with SHA(); 7.8 Decrypting Comparing passwords; 7.9 Authorizing users with HTTP; 7.10 Logging In Users with HTTP Authentication; 7.11 A form for signing up new users; 7.12 Give users a chance to sign up; 7.13 Sometimes you just need a cookie; 7.14 What''s in a cookie?; 7.15 Bake Use cookies with PHP; 7.16 Rethinking the flow of log-ins; 7.17 A cookie-powered log-in; 7.18 Navigating the Mismatch application; 7.19 Logging out means deleting cookies; 7.20 Sessions aren''t dependent on the client; 7.21 The life and times of sessions; 7.22 Keeping up with session data; 7.23 Renovate Mismatch with sessions; 7.24 Log out with sessions; 7.25 Complete the session transformation; 7.26 Users aren''t feeling welcome; 7.27 Sessions are short-lived...; 7.28 ... but cookies can last forever!; 7.29 Sessions + Cookies = Superior log-in persistence; Chapter 8: Eliminate Duplicate Code: Sharing is caring; 8.1 Mismatch is in pieces; 8.2 Rebuilding Mismatch from a template; 8.3 Rebuild Mismatch with templates; 8.4 Mismatch is whole again... and much better organized; Chapter 9: Control your Data, Control your World: Harvesting data; 9.1 Making the perfect mismatch; 9.2 Mismatching is all about the data; 9.3 Break down the Mismatch data; 9.4 Model a database with a schema; 9.5 Wire together multiple tables; 9.6 Foreign keys in action; 9.7 Tables can match row for row; 9.8 One row leads to many; 9.9 Matching rows many-to-many; 9.10 Build a Mismatch questionnaire; 9.11 Get responses into the database; 9.12 We can drive a form with data; 9.13 Speaking of efficiency...; 9.14 Generate the Mismatch questionnaire form; 9.15 The data is now driving the form; 9.16 Strive for a bit of normalcy; 9.17 When normalizing, think in atoms; 9.18 Why be normal, really?; 9.19 Three steps to a normal database; 9.20 Altering the Mismatch database; 9.21 So is Mismatch really normal?; 9.22 A query within a query within a query...; 9.23 Let''s all join hands tables; 9.24 Connect the with dots; 9.25 Surely we can do more with inner joins; 9.26 Simplifying ON with USING; 9.27 Nicknames for tables and columns; 9.28 Joins to the rescue; 9.29 Love is a numbers game; 9.30 Five steps to a successful mismatch; 9.31 Prepare for the mismatch search; 9.32 Compare users for "mismatchiness"; 9.33 All we need is a FOR loop; 9.34 Finishing the mismatching; 9.35 Your PHP & MySQL Toolbox; Chapter 10: String and Custom Functions: Better living through functions; 10.1 A good risky job is hard to find; 10.2 The search leaves no margin for error; 10.3 SQL queries can be flexible with LIKE; 10.4 Explode a string into individual words; 10.5 implode() builds a string from substrings; 10.6 Preprocess the search string; 10.7 Replace unwanted search characters; 10.8 The query needs legit search terms; 10.9 Copy non-empty elements to a new array; 10.10 Sometimes you just need part of a string; 10.11 Extract substrings from either end; 10.12 Multiple queries can sort our results; 10.13 Functions let you reuse code; 10.14 Build a query with a custom function; 10.15 SWITCH makes far more decisions than IF; 10.16 Give build_query() the ability to sort; 10.17 We can paginate our results; 10.18 Get only the rows you need with LIMIT; 10.19 Control page links with LIMIT; 10.20 Keep track of the pagination data; 10.21 Set up the pagination variables; 10.22 Revise the query for paginated results; 10.23 Generate the page navigation links; 10.24 Putting together the complete Search script; 10.25 The complete Search script, continued...; 10.26 Your PHP & MySQL Toolbox; Chapter 11: Regular Expressions: Rules for replacement; 11.1 Risky Jobs lets users submit resumes; 11.2 Decide what your data should look like; 11.3 Formulate a pattern for phone numbers; 11.4 Match patterns with regular expressions; 11.5 Build patterns using metacharacters; 11.6 Fine-tune patterns with character classes; 11.7 Check for patterns with preg_match(); 11.8 Standardize the phone number data; 11.9 Get rid of the unwanted characters; 11.10 Matching email addresses can be tricky; 11.11 Domain suffixes are everywhere; 11.12 Use PHP to check the domain; 11.13 Email validation: putting it all together; 11.14 Your PHP & MySQL Toolbox; Chapter 12: Visualizing your Data... and More!: Drawing dynamic graphics; 12.1 Guitar Wars Reloaded: Rise of the Machines; 12.2 No input form is safe; 12.3 We need to separate man from machine; 12.4 We can defeat automation with automation; 12.5 Generate the CAPTCHA pass-phrase text; 12.6 Visualizing the CAPTCHA image; 12.7 Inside the GD graphics functions; 12.8 The GD graphics functions continued...; 12.9 Drawing text with a font; 12.10 Generate a random CAPTCHA image; 12.11 Returning sanity to Guitar Wars; 12.12 Add CAPTCHA to the Add Score script; 12.13 Five degrees of opposability; 12.14 Charting mismatchiness; 12.15 Storing bar graph data; 12.16 From one array to another; 12.17 Build an array of mismatched topics; 12.18 Formulating a bar graphing plan; 12.19 Crunching categories; 12.20 Doing the category math; 12.21 Bar graphing basics; 12.22 Draw and display the bar graph image; 12.23 Individual bar graph images for all; 12.24 Mismatch users are digging the bar graphs; 12.25 Your PHP & MySQL Toolbox; Chapter 13: Syndication and Web Services: Interfacing to the world; 13.1 Owen needs to get the word out about Fang; 13.2 Push alien abduction data to the people; 13.3 RSS pushes web content to the people; 13.4 RSS is really XML; 13.5 From database to newsreader; 13.6 Visualizing XML RSS; 13.7 Dynamically generate an RSS feed; 13.8 Link to the RSS feed; 13.9 A picture video is worth a thousand million words; 13.10 Pulling web content from others; 13.11 Syndicating YouTube videos; 13.12 Make a YouTube video request; 13.13 Owen is ready to build a REST request; 13.14 YouTube speaks XML; 13.15 Deconstruct a YouTube XML response; 13.16 Visualize the XML video data; 13.17 Access XML data with objects; 13.18 From XML elements to PHP objects; 13.19 Drill into XML data with objects; 13.20 Not without a namespace!; 13.21 Fang sightings are on the rise; 13.22 Lay out videos for viewing; 13.23 Format video data for display; 13.24 Your PHP & MySQL Toolbox; Leftovers: The Top Ten Topics (we didn''t cover); #1. Retrofit this book for PHP4 and mysql functions; #2. User permissions in MySQL; #3. Error reporting for MySQL; #4. Exception handling PHP errors; #4. Exception handling PHP errors (cont.); #5. Object-oriented PHP; #5. Object-oriented PHP (cont.); #6. Securing your PHP application; #6. Securing your PHP application (cont.); #7. Protect your app from cross-site scripting; #7. Protect your app from cross-site scripting (cont.); #8. Operator precedence; #9. What''s the difference between PHP 5 and PHP 6; #9. What''s the difference between PHP 5 and PHP 6 (cont.); #10. Reusing other people''s PHP; Set up a Development Environment: A place to play; Create a PHP development environment; Find out what you have; Do you have a web server?; Do you have PHP? Which version?; Do you have MySQL? Which version?; Start with the Web Server; Apache installation... concluded; PHP installation; PHP installation steps; PHP installation steps... concluded; Installing MySQL; Steps to Install MySQL on Windows; Enabling PHP on Mac OS X; Steps to Install MySQL on Mac OS X; Moving from production to a live site; Dump your data (and your tables); Prepare to use your dumped data; Move dumped data to the live server; Connect to the live server; Extend your PHP: Get even more; Extending your PHP; And on the Mac...;