You are previewing Learning PHP, MySQL, JavaScript, CSS & HTML5, 3rd Edition.
O'Reilly logo
Learning PHP, MySQL, JavaScript, CSS & HTML5, 3rd Edition

Book Description

Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you only have basic HTML knowledge. With this popular hands-on guide, you’ll tackle dynamic web programming with the help of today’s core technologies: PHP, MySQL, JavaScript, CSS, and HTML5.

Table of Contents

  1. Dedication
  2. Preface
    1. Audience
    2. Assumptions This Book Makes
    3. Organization of This Book
    4. Supporting Books
    5. Conventions Used in This Book
    6. Using Code Examples
    7. We’d Like to Hear from You
    8. Safari® Books Online
    9. Acknowledgments
  3. 1. Introduction to Dynamic Web Content
    1. HTTP and HTML: Berners-Lee’s Basics
    2. The Request/Response Procedure
    3. The Benefits of PHP, MySQL, JavaScript, CSS, and HTML5
      1. Using PHP
      2. Using MySQL
      3. Using JavaScript
      4. Using CSS
    4. And Then There’s HTML5
    5. The Apache Web Server
    6. About Open Source
    7. Bringing It All Together
    8. Questions
  4. 2. Setting Up a Development Server
    1. What Is a WAMP, MAMP, or LAMP?
    2. Installing a WAMP on Windows
      1. Testing the Installation
      2. Alternative WAMPs
    3. Installing a MAMP on Mac OS X
      1. Configuring MySQL
      2. Ensuring MySQL Starts on Booting
      3. Testing the Installation
    4. Installing a LAMP on Linux
    5. Working Remotely
      1. Logging In
      2. Using FTP
    6. Using a Program Editor
    7. Using an IDE
    8. Questions
  5. 3. Introduction to PHP
    1. Incorporating PHP Within HTML
    2. This Book’s Examples
    3. The Structure of PHP
      1. Using Comments
      2. Basic Syntax
        1. Semicolons
        2. The $ symbol
      3. Variables
        1. String variables
        2. Numeric variables
        3. Arrays
        4. Two-dimensional arrays
        5. Variable naming rules
      4. Operators
        1. Arithmetic operators
        2. Assignment operators
        3. Comparison operators
        4. Logical operators
      5. Variable Assignment
        1. Variable incrementing and decrementing
        2. String concatenation
        3. String types
        4. Escaping characters
      6. Multiple-Line Commands
      7. Variable Typing
      8. Constants
      9. Predefined Constants
      10. The Difference Between the echo and print Commands
      11. Functions
      12. Variable Scope
        1. Local variables
        2. Global variables
        3. Static variables
        4. Superglobal variables
        5. Superglobals and security
    4. Questions
  6. 4. Expressions and Control Flow in PHP
    1. Expressions
      1. TRUE or FALSE?
      2. Literals and Variables
    2. Operators
      1. Operator Precedence
      2. Associativity
      3. Relational Operators
        1. Equality
        2. Comparison operators
        3. Logical operators
    3. Conditionals
      1. The if Statement
      2. The else Statement
      3. The elseif Statement
      4. The switch Statement
        1. Breaking out
        2. Default action
        3. Alternative syntax
      5. The ? Operator
    4. Looping
      1. while Loops
      2. do ... while Loops
      3. for Loops
      4. Breaking Out of a Loop
      5. The continue Statement
    5. Implicit and Explicit Casting
    6. PHP Dynamic Linking
    7. Dynamic Linking in Action
    8. Questions
  7. 5. PHP Functions and Objects
    1. PHP Functions
      1. Defining a Function
      2. Returning a Value
      3. Returning an Array
      4. Passing by Reference
      5. Returning Global Variables
      6. Recap of Variable Scope
    2. Including and Requiring Files
      1. The include Statement
      2. Using include_once
      3. Using require and require_once
    3. PHP Version Compatibility
    4. PHP Objects
      1. Terminology
      2. Declaring a Class
      3. Creating an Object
      4. Accessing Objects
      5. Cloning Objects
      6. Constructors
      7. PHP 5 Destructors
      8. Writing Methods
      9. Static Methods in PHP 5
      10. Declaring Properties
      11. Declaring Constants
      12. Property and Method Scope in PHP 5
      13. Static Properties and Methods
      14. Inheritance
        1. The parent operator
        2. Subclass constructors
        3. Final methods
    5. Questions
  8. 6. PHP Arrays
    1. Basic Access
      1. Numerically Indexed Arrays
      2. Associative Arrays
      3. Assignment Using the array Keyword
    2. The foreach ... as Loop
    3. Multidimensional Arrays
    4. Using Array Functions
      1. is_array
      2. count
      3. sort
      4. shuffle
      5. explode
      6. extract
      7. compact
      8. reset
      9. end
    5. Questions
  9. 7. Practical PHP
    1. Using printf
      1. Precision Setting
      2. String Padding
      3. Using sprintf
    2. Date and Time Functions
      1. Date Constants
      2. Using checkdate
    3. File Handling
      1. Checking Whether a File Exists
      2. Creating a File
      3. Reading from Files
      4. Copying Files
      5. Moving a File
      6. Deleting a File
      7. Updating Files
      8. Locking Files for Multiple Accesses
      9. Reading an Entire File
      10. Uploading Files
        1. Using $_FILES
        2. Validation
    4. System Calls
    5. XHTML or HTML5?
    6. Questions
  10. 8. Introduction to MySQL
    1. MySQL Basics
    2. Summary of Database Terms
    3. Accessing MySQL via the Command Line
      1. Starting the Command-Line Interface
        1. Windows users
        2. OS X users
        3. Linux users
        4. MySQL on a remote server
      2. Using the Command-Line Interface
        1. The semicolon
        2. Canceling a command
      3. MySQL Commands
        1. Creating a database
        2. Creating users
        3. Creating a table
      4. Data Types
        1. The CHAR data type
        2. The BINARY data type
        3. The TEXT and VARCHAR data types
        4. The BLOB data type
        5. Numeric data types
        6. DATE and TIME
        7. The AUTO_INCREMENT data type
        8. Adding data to a table
        9. Renaming a table
        10. Changing the data type of a column
        11. Adding a new column
        12. Renaming a column
        13. Removing a column
        14. Deleting a table
    4. Indexes
      1. Creating an Index
        1. Using CREATE INDEX
        2. Adding indexes when creating tables
        3. Primary keys
        4. Creating a FULLTEXT index
      2. Querying a MySQL Database
        1. SELECT
        2. SELECT COUNT
        3. SELECT DISTINCT
        4. DELETE
        5. WHERE
        6. LIMIT
        7. MATCH ... AGAINST
        8. MATCH ... AGAINST ... IN BOOLEAN MODE
        9. UPDATE ... SET
        10. ORDER BY
        11. GROUP BY
      3. Joining Tables Together
        1. NATURAL JOIN
        2. JOIN...ON
        3. Using AS
      4. Using Logical Operators
    5. MySQL Functions
    6. Accessing MySQL via phpMyAdmin
    7. Using phpMyAdmin
    8. Questions
  11. 9. Mastering MySQL
    1. Database Design
    2. Primary Keys: The Keys to Relational Databases
    3. Normalization
      1. First Normal Form
      2. Second Normal Form
      3. Third Normal Form
      4. When Not to Use Normalization
    4. Relationships
      1. One-to-One
      2. One-to-Many
      3. Many-to-Many
      4. Databases and Anonymity
    5. Transactions
      1. Transaction Storage Engines
      2. Using BEGIN
      3. Using COMMIT
      4. Using ROLLBACK
    6. Using EXPLAIN
    7. Backing Up and Restoring
      1. Using mysqldump
      2. Creating a Backup File
        1. Backing up a single table
        2. Backing up all tables
      3. Restoring from a Backup File
      4. Dumping Data in CSV Format
      5. Planning Your Backups
    8. Questions
  12. 10. Accessing MySQL Using PHP
    1. Querying a MySQL Database with PHP
      1. The Process
      2. Creating a Login File
      3. Connecting to MySQL
        1. Selecting a database
        2. Building and executing a query
        3. Fetching a result
        4. Fetching a row
        5. Closing a connection
    2. A Practical Example
      1. The $_POST Array
      2. Deleting a Record
      3. Displaying the Form
      4. Querying the Database
      5. Running the Program
    3. Practical MySQL
      1. Creating a Table
      2. Describing a Table
      3. Dropping a Table
      4. Adding Data
      5. Retrieving Data
      6. Updating Data
      7. Deleting Data
      8. Using AUTO_INCREMENT
        1. Using insert IDs
        2. Using locks
      9. Performing Additional Queries
      10. Preventing SQL Injection
      11. Using Placeholders
      12. Preventing HTML Injection
    4. Questions
  13. 11. Using the mysqli Extension
    1. Querying a MySQL Database with mysqli
      1. Creating a Login File
      2. Connecting to MySQL
        1. Building and executing a query
        2. Fetching a result
        3. Fetching a row
        4. Closing a connection
    2. A Practical Example
    3. Using mysqli Procedurally
    4. Questions
  14. 12. Form Handling
    1. Building Forms
    2. Retrieving Submitted Data
      1. register_globals: An Old Solution Hangs On
      2. Default Values
      3. Input Types
        1. Text boxes
        2. Text areas
        3. Checkboxes
        4. Radio buttons
        5. Hidden fields
        6. <select>
        7. Labels
        8. The submit button
      4. Sanitizing Input
    3. An Example Program
    4. What’s New in HTML5?
      1. The autocomplete Attribute
      2. The autofocus Attribute
      3. The placeholder Attribute
      4. The required Attribute
      5. Override Attributes
      6. The width and height Attributes
    5. Features Awaiting Full Implementation
      1. The form Attribute
      2. The list Attribute
      3. The min and max Attributes
      4. The step Attribute
      5. The color Input Type
      6. The number and range Input Types
      7. Date and time Pickers
    6. Questions
  15. 13. Cookies, Sessions, and Authentication
    1. Using Cookies in PHP
      1. Setting a Cookie
      2. Accessing a Cookie
      3. Destroying a Cookie
    2. HTTP Authentication
      1. Storing Usernames and Passwords
      2. Salting
    3. Using Sessions
      1. Starting a Session
      2. Ending a Session
      3. Setting a Timeout
      4. Session Security
        1. Preventing session hijacking
        2. Preventing session fixation
        3. Forcing cookie-only sessions
        4. Using a shared server
    4. Questions
  16. 14. Exploring JavaScript
    1. JavaScript and HTML Text
      1. Using Scripts Within a Document Head
      2. Older and Nonstandard Browsers
      3. Including JavaScript Files
      4. Debugging JavaScript Errors
    2. Using Comments
    3. Semicolons
    4. Variables
      1. String Variables
      2. Numeric Variables
      3. Arrays
    5. Operators
      1. Arithmetic Operators
      2. Assignment Operators
      3. Comparison Operators
      4. Logical Operators
      5. Variable Incrementing and Decrementing
      6. String Concatenation
      7. Escaping Characters
    6. Variable Typing
    7. Functions
    8. Global Variables
    9. Local Variables
    10. The Document Object Model
      1. But It’s Not That Simple
      2. Another Use for the $ Symbol
      3. Using the DOM
    11. Questions
  17. 15. Expressions and Control Flow in JavaScript
    1. Expressions
    2. Literals and Variables
    3. Operators
      1. Operator Precedence
      2. Associativity
      3. Relational Operators
        1. Equality operators
        2. Comparison operators
        3. Logical operators
    4. The with Statement
    5. Using onerror
    6. Using try ... catch
    7. Conditionals
      1. The if Statement
      2. The else Statement
      3. The switch statement
        1. Breaking out
        2. Default action
      4. The ? Operator
    8. Looping
      1. while Loops
      2. do ... while Loops
      3. for Loops
      4. Breaking Out of a Loop
      5. The continue Statement
    9. Explicit Casting
    10. Questions
  18. 16. JavaScript Functions, Objects, and Arrays
    1. JavaScript Functions
      1. Defining a Function
      2. The arguments Array
      3. Returning a Value
      4. Returning an Array
    2. JavaScript Objects
      1. Declaring a Class
      2. Creating an Object
      3. Accessing Objects
      4. The prototype Keyword
        1. Static methods and properties
        2. Extending JavaScript objects
    3. JavaScript Arrays
      1. Numeric Arrays
        1. Assigning element values
        2. Assignment using the array keyword
      2. Associative Arrays
      3. Multidimensional Arrays
      4. Using Array Methods
        1. concat
        2. forEach (for non-IE browsers)
        3. forEach (a cross-browser solution)
        4. join
        5. push and pop
        6. Using reverse
        7. sort
    4. Questions
  19. 17. JavaScript and PHP Validation and Error Handling
    1. Validating User Input with JavaScript
      1. The validate.html Document (Part One)
      2. The validate.html Document (Part Two)
        1. Validating the forename
        2. Validating the surname
        3. Validating the username
        4. Validating the password
        5. Validating the age
        6. Validating the email
        7. Using a separate JavaScript file
    2. Regular Expressions
      1.  
        1. Matching through metacharacters
        2. Fuzzy character matching
        3. Grouping through parentheses
        4. Character classes
        5. Indicating a range
        6. Negation
        7. Some more complicated examples
        8. Summary of metacharacters
        9. General modifiers
      2. Using Regular Expressions in JavaScript
      3. Using Regular Expressions in PHP
    3. Redisplaying a Form After PHP Validation
    4. Questions
  20. 18. Using Ajax
    1. What Is Ajax?
    2. Using XMLHttpRequest
      1. Your First Ajax Program
        1. The readyState property
        2. The server half of the Ajax process
      2. Using GET Instead of POST
      3. Sending XML Requests
        1. About XML
        2. Why use XML?
      4. Using Frameworks for Ajax
    3. Questions
  21. 19. Introduction to CSS
    1. Importing a Style Sheet
      1. Importing CSS from Within HTML
      2. Embedded Style Settings
    2. Using IDs
    3. Using Classes
    4. Using Semicolons
    5. CSS Rules
      1. Multiple Assignments
      2. Using Comments
    6. Style Types
      1. Default Styles
      2. User Styles
      3. External Style Sheets
      4. Internal Styles
      5. Inline Styles
    7. CSS Selectors
      1. The Type Selector
      2. The Descendant Selector
      3. The Child Selector
      4. The ID Selector
      5. The Class Selector
      6. The Attribute Selector
      7. The Universal Selector
      8. Selecting by Group
    8. The CSS Cascade
      1. Style Sheet Creators
      2. Style Sheet Methods
      3. Style Sheet Selectors
      4. Calculating Specificity
        1. Using a different number base
        2. Some rules are more equal than others
      5. The Difference Between Div and Span Elements
    9. Measurements
    10. Fonts and Typography
      1. font-family
      2. font-style
      3. font-size
      4. font-weight
    11. Managing Text Styles
      1. Decoration
      2. Spacing
      3. Alignment
      4. Transformation
      5. Indenting
    12. CSS Colors
      1. Short Color Strings
      2. Gradients
    13. Positioning Elements
      1. Absolute Positioning
      2. Relative Positioning
      3. Fixed Positioning
    14. Pseudo-Classes
    15. Shorthand Rules
    16. The Box Model and Layout
      1. Setting Margins
      2. Applying Borders
      3. Adjusting Padding
      4. Object Contents
    17. Questions
  22. 20. Advanced CSS with CSS3
    1. Attribute Selectors
      1. The ^ Operator
      2. The $ Operator
      3. The * Operator
    2. The box-sizing Property
    3. CSS3 Backgrounds
      1. The background-clip Property
      2. The background-origin Property
      3. The background-size Property
    4. Multiple Backgrounds
    5. CSS3 Borders
      1. The border-color Property
      2. The border-radius Property
    6. Box Shadows
    7. Element Overflow
    8. Multicolumn Layout
    9. Colors and Opacity
      1. HSL Colors
      2. HSLA Colors
      3. RGB Colors
      4. RGBA Colors
      5. The opacity Property
    10. Text Effects
      1. The text-shadow Property
      2. The text-overflow Property
      3. The word-wrap Property
    11. Web Fonts
    12. Google Web Fonts
    13. Transformations
    14. 3D Transformations
    15. Transitions
      1. Properties to Transition
      2. Transition Duration
      3. Transition Delay
      4. Transition Timing
      5. Shorthand Syntax
    16. Questions
  23. 21. Accessing CSS from JavaScript
    1. Revisiting the getElementById Function
      1. The O function
      2. The S Function
      3. The C Function
      4. Including the Functions
    2. Accessing CSS Properties from JavaScript
      1. Some Common Properties
      2. Other Properties
    3. Inline JavaScript
      1. The this Keyword
      2. Attaching Events to Objects in a Script
      3. Attaching to Other Events
    4. Adding New Elements
      1. Removing Elements
      2. Alternatives to Adding and Removing Elements
    5. Using Interrupts
      1. Using setTimeout
        1. Passing a string
        2. Repeating timeouts
      2. Canceling a Timeout
      3. Using setInterval
        1. Using the function
        2. Canceling an interval
      4. Using Interrupts for Animation
    6. Questions
  24. 22. Introduction to HTML5
    1. The Canvas
    2. Geolocation
    3. Audio and Video
    4. Forms
    5. Local Storage
    6. Web Workers
    7. Web Applications
    8. Microdata
    9. Summary
    10. Questions
  25. 23. The HTML5 Canvas
    1. Creating and Accessing a Canvas
      1. The toDataURL Function
      2. Specifying an Image Type
      3. The fillRect Method
      4. The clearRect Method
      5. The strokeRect Method
      6. Combining These Commands
      7. The createLinearGradient Method
      8. The addColorStop Method in Detail
      9. The createRadialGradient Method
      10. Using Patterns for Fills
    2. Writing Text to the Canvas
      1. The strokeText Method
      2. The textBaseLine Property
      3. The font Property
      4. The textAlign Property
      5. The fillText Method
      6. The measureText Method
    3. Drawing Lines
      1. The lineWidth Property
      2. The lineCap and lineJoin Properties
      3. The miterLimit Property
    4. Using Paths
      1. The moveTo and LineTo Methods
      2. The stroke Method
      3. The rect Method
    5. Filling Areas
    6. The clip Method
    7. The isPointInPath Method
    8. Working with Curves
      1. The arc Method
      2. The arcTo Method
      3. The quadraticCurveTo Method
      4. The bezierCurveTo Method
    9. Manipulating Images
      1. The drawImage Method
      2. Resizing an Image
      3. Selecting an Image Area
      4. Copying from a Canvas
      5. Adding Shadows
    10. Editing at the Pixel Level
      1. The getImageData Method
      2. The data Array
      3. The putImageData Method
      4. The createImageData Method
    11. Advanced Graphical Effects
      1. The globalCompositeOperation Property
      2. The globalAlpha Property
    12. Transformations
      1. The scale Method
      2. The save and restore Methods
      3. The rotate Method
      4. The translate Method
      5. The transform Method
      6. The setTransform Method
    13. Summary
    14. Questions
  26. 24. HTML5 Audio and Video
    1. About Codecs
    2. The <audio> Element
    3. Supporting Non-HTML5 Browsers
    4. The <video> Element
      1. The Video Codecs
      2. Supporting Older Browsers
    5. Summary
    6. Questions
  27. 25. Other HTML5 Features
    1. Geolocation and the GPS Service
    2. Other Location Methods
    3. Geolocation and HTML5
    4. Local Storage
      1. Using Local Storage
      2. The localStorage Object
    5. Web Workers
    6. Offline Web Applications
    7. Drag and Drop
    8. Cross Document Messaging
    9. Microdata
    10. Other HTML5 Tags
    11. Summary
    12. Questions
  28. 26. Bringing It All Together
    1. Designing a Social Networking Site
    2. On the Website
    3. functions.php
    4. The Functions
    5. header.php
    6. setup.php
    7. index.php
    8. signup.php
      1. Checking for Username Availability
      2. Logging In
    9. checkuser.php
    10. login.php
    11. profile.php
      1. Adding the “About Me” Text
      2. Adding a Profile Image
      3. Processing the Image
      4. Displaying the Current Profile
    12. members.php
      1. Viewing a User’s Profile
      2. Adding and Dropping Friends
      3. Listing All Members
    13. friends.php
    14. messages.php
    15. logout.php
    16. styles.css
    17. javascript.js
  29. A. Solutions to the Chapter Questions
    1. Chapter 1 Answers
    2. Chapter 2 Answers
    3. Chapter 3 Answers
    4. Chapter 4 Answers
    5. Chapter 5 Answers
    6. Chapter 6 Answers
    7. Chapter 7 Answers
    8. Chapter 8 Answers
    9. Chapter 9 Answers
    10. Chapter 10 Answers
    11. Chapter 11 Answers
    12. Chapter 12 Answers
    13. Chapter 13 Answers
    14. Chapter 14 Answers
    15. Chapter 15 Answers
    16. Chapter 16 Answers
    17. Chapter 17 Answers
    18. Chapter 18 Answers
    19. Chapter 19 Answers
    20. Chapter 20 Answers
    21. Chapter 21 Answers
    22. Chapter 22 Answers
    23. Chapter 23 Answers
    24. Chapter 24 Answers
    25. Chapter 25 Answers
  30. B. Online Resources
    1. PHP Resource Sites
    2. MySQL Resource Sites
    3. JavaScript Resource Sites
    4. CSS Resource Sites
    5. HTML5 Resource Sites
    6. AJAX Resource Sites
    7. Miscellaneous Resource Sites
    8. O’Reilly Resource Sites
  31. C. MySQL’s FULLTEXT Stopwords
  32. D. MySQL Functions
    1. String Functions
    2. Date Functions
    3. Time Functions
  33. Index
  34. Colophon
  35. Copyright