Learning PHP, MySQL & JavaScript, 4th Edition

Book description

Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only 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, jQuery, CSS, and HTML5.

Publisher resources

View/Submit Errata

Table of contents

  1. 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. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgments
  2. 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
  3. 2. Setting Up a Development Server
    1. What Is a WAMP, MAMP, or LAMP?
    2. Installing XAMPP on Windows
      1. Testing the Installation
    3. Installing XAMPP on Mac OS X
      1. Accessing the Document Root
    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
  4. 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
      3. Variables
      4. Operators
      5. Variable Assignment
      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
    4. Questions
  5. 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
    3. Conditionals
      1. The if Statement
      2. The else Statement
      3. The elseif Statement
      4. The switch Statement
      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
  6. 5. PHP Functions and Objects
    1. PHP Functions
      1. Defining a Function
      2. Returning a Value
      3. Returning an Array
      4. Do Not Pass Arguments 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
    5. Questions
  7. 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
  8. 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
    4. System Calls
    5. XHTML or HTML5?
    6. Questions
  9. 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
      2. Using the Command-Line Interface
      3. MySQL Commands
      4. Data Types
    4. Indexes
      1. Creating an Index
      2. Querying a MySQL Database
      3. Joining Tables Together
      4. Using Logical Operators
    5. MySQL Functions
    6. Accessing MySQL via phpMyAdmin
    7. Questions
  10. 9. Mastering MySQL
    1. Database Design
      1. Primary Keys: The Keys to Relational Databases
    2. Normalization
      1. First Normal Form
      2. Second Normal Form
      3. Third Normal Form
      4. When Not to Use Normalization
    3. Relationships
      1. One-to-One
      2. One-to-Many
      3. Many-to-Many
      4. Databases and Anonymity
    4. Transactions
      1. Transaction Storage Engines
      2. Using BEGIN
      3. Using COMMIT
      4. Using ROLLBACK
    5. Using EXPLAIN
    6. Backing Up and Restoring
      1. Using mysqldump
      2. Creating a Backup File
      3. Restoring from a Backup File
      4. Dumping Data in CSV Format
      5. Planning Your Backups
    7. Questions
  11. 10. Accessing MySQL Using PHP
    1. Querying a MySQL Database with PHP
      1. The Process
      2. Creating a Login File
      3. Connecting to a MySQL Database
    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
      9. Performing Additional Queries
    4. Preventing Hacking Attempts
      1. Steps You Can Take
      2. Using Placeholders
      3. Preventing HTML Injection
    5. Using mysqli Procedurally
    6. Questions
  12. 11. Form Handling
    1. Building Forms
    2. Retrieving Submitted Data
      1. register_globals: An Old Solution Hangs On
      2. Default Values
      3. Input Types
      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
  13. 12. 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 Time-Out
      4. Session Security
    4. Questions
  14. 13. 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. Using the DOM
    11. About document.write
      1. Using console.log
      2. Using alert
      3. Writing into Elements
      4. Using document.write
    12. Questions
  15. 14. Expressions and Control Flow in JavaScript
    1. Expressions
    2. Literals and Variables
    3. Operators
      1. Operator Precedence
      2. Associativity
      3. Relational 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
      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
  16. 15. JavaScript Functions, Objects, and Arrays
    1. JavaScript Functions
      1. Defining a Function
      2. Returning a Value
      3. Returning an Array
    2. JavaScript Objects
      1. Declaring a Class
      2. Creating an Object
      3. Accessing Objects
      4. The prototype Keyword
    3. JavaScript Arrays
      1. Numeric Arrays
      2. Associative Arrays
      3. Multidimensional Arrays
      4. Using Array Methods
    4. Questions
  17. 16. JavaScript and PHP Validation and Error Handling
    1. Validating User Input with JavaScript
      1. The validate.html Document (Part 1)
      2. The validate.html Document (Part 2)
    2. Regular Expressions
      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
      10. Using Regular Expressions in JavaScript
      11. Using Regular Expressions in PHP
    3. Redisplaying a Form After PHP Validation
    4. Questions
  18. 17. Using Ajax
    1. What Is Ajax?
    2. Using XMLHttpRequest
      1. Your First Ajax Program
      2. Using Get Instead of Post
      3. Sending XML Requests
      4. Using Frameworks for Ajax
    3. Questions
  19. 18. 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
      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. Pseudoclasses
    15. Shorthand Rules
    16. The Box Model and Layout
      1. Setting Margins
      2. Applying Borders
      3. Adjusting Padding
      4. Object Contents
    17. Questions
  20. 19. Advanced CSS with CSS3
    1. Attribute Selectors
      1. Matching Parts of Strings
    2. The box-sizing Property
    3. CSS3 Backgrounds
      1. The background-clip Property
      2. The background-origin Property
      3. The background-size Property
      4. Using the auto Value
    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
  21. 20. 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
      2. Cancelling a Time-Out
      3. Using setInterval
      4. Using Interrupts for Animation
    6. Questions
  22. 21. Introduction to jQuery
    1. Why jQuery?
    2. Including jQuery
      1. Choosing the Right Version
      2. Downloading
      3. Using a Content Delivery Network
      4. Always Using the Latest Version
      5. Customizing jQuery
    3. jQuery Syntax
      1. A Simple Example
      2. Avoiding Library Conflict
    4. Selectors
      1. The css Method
      2. The Element Selector
      3. The ID Selector
      4. The Class Selector
      5. Combining Selectors
    5. Handling Events
    6. Waiting Until the Document Is Ready
    7. Event Functions and Properties
      1. The blur and focus Events
      2. The this Keyword
      3. The click and dblclick Events
      4. The keypress Event
      5. Considerate Programming
      6. The mousemove Event
      7. Other Mouse Events
      8. Alternative Mouse Methods
      9. The submit Event
    8. Special Effects
      1. Hiding and Showing
      2. The toggle Method
      3. Fading In and Out
      4. Sliding Elements Up and Down
      5. Animations
      6. Stopping Animations
    9. Manipulating the DOM
      1. The Difference Between The text and html Methods
      2. The val and attr Methods
      3. Adding and Removing Elements
    10. Dynamically Applying Classes
    11. Modifying Dimensions
      1. The width and height Methods
      2. The innerWidth and innerHeight Methods
      3. The outerWidth and OuterHeight Methods
    12. DOM Traversal
      1. Parent Elements
      2. Child Elements
      3. Sibling Elements
      4. Selecting the Next and Previous Elements
      5. Traversing jQuery Selections
      6. The is Method
    13. Using jQuery Without Selectors
      1. The $.each Method
      2. The $.map Method
    14. Using Ajax
      1. Using the Post Method
      2. Using the Get Method
    15. Plug-Ins
      1. The jQuery User Interface
      2. Other Plug-Ins
      3. jQuery Mobile
    16. Questions
  23. 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
  24. 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
  25. 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
  26. 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
  27. 26. Bringing It All Together
    1. Designing a Social Networking Site
    2. On the Website
    3. functions.php
      1. The Functions
    4. header.php
    5. setup.php
    6. index.php
    7. signup.php
      1. Checking for Username Availability
      2. Logging In
    8. checkuser.php
    9. login.php
    10. profile.php
      1. Adding the “About Me” Text
      2. Adding a Profile Image
      3. Processing the Image
      4. Displaying the Current Profile
    11. members.php
      1. Viewing a User’s Profile
      2. Adding and Dropping Friends
      3. Listing All Members
    12. friends.php
    13. messages.php
    14. logout.php
    15. styles.css
    16. javascript.js
  28. 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
  29. 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
  30. C. MySQL’s FULLTEXT Stopwords
  31. D. MySQL Functions
    1. String Functions
    2. Date Functions
    3. Time Functions
  32. E. jQuery Selectors, Objects, and Methods
    1. jQuery Selectors
    2. jQuery Objects
    3. jQuery Methods
  33. Index

Product information

  • Title: Learning PHP, MySQL & JavaScript, 4th Edition
  • Author(s):
  • Release date: December 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491918661