Learning PHP, MySQL & JavaScript, 5th 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. In this update to this popular hands-on guide, you’ll tackle dynamic web programming with the latest versions of today’s core technologies: PHP, MySQL, JavaScript, CSS, HTML5, and key jQuery libraries.

Web designers will learn how to use these technologies together and pick up valuable web programming practices along the way—including how to optimize websites for mobile devices. At the end of the book, you’ll put everything together to build a fully functional social networking site suitable for both desktop and mobile browsers.

  • Explore MySQL, from database structure to complex queries
  • Use the MySQLi extension, PHP’s improved MySQL interface
  • Create dynamic PHP web pages that tailor themselves to the user
  • Manage cookies and sessions and maintain a high level of security
  • Enhance the JavaScript language with jQuery and jQuery mobile libraries
  • Use Ajax calls for background browser-server communication
  • Style your web pages by acquiring CSS2 and CSS3 skills
  • Implement HTML5 features, including geolocation, audio, video, and the canvas element
  • Reformat your websites into mobile web apps

Publisher resources

View/Submit Errata

Table of contents

  1. Learning PHP, MySQL & JavaScript
  2. Learning PHP, MySQL & JavaScript
  3. Dedication
  4. 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. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  5. 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. MariaDB: The MySQL Clone
      2. Using PHP
      3. Using MySQL
      4. Using JavaScript
      5. Using CSS
    4. And Then There’s HTML5
    5. The Apache Web Server
    6. Handling Mobile Devices
    7. About Open Source
    8. Bringing It All Together
    9. Questions
  6. 2. Setting Up a Development Server
    1. What Is a WAMP, MAMP, or LAMP?
    2. Installing AMPPS on Windows
      1. Testing the Installation
      2. Accessing the Document Root (Windows)
      3. Alternative WAMPs
    3. Installing AMPPS on macOS
      1. Accessing the Document Root (macOS)
    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
  7. 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
  8. 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
  9. 5. PHP Functions and Objects
    1. PHP Functions
      1. Defining a Function
      2. Returning a Value
      3. Returning an Array
      4. Passing 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. Destructors
      8. Writing Methods
      9. Declaring Properties
      10. Declaring Constants
      11. Property and Method Scope
      12. Static Methods
      13. Static Properties
      14. Inheritance
    5. Questions
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 11. Form Handling
    1. Building Forms
    2. Retrieving Submitted Data
      1. Default Values
      2. Input Types
      3. Sanitizing Input
    3. An Example Program
    4. HTML5 Enhancements
      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
      7. The min and max Attributes
      8. The step Attribute
      9. The form Attribute
      10. The list Attribute
      11. The color Input Type
      12. The number and range Input Types
      13. Date and Time Pickers
    5. Questions
  16. 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. An Example Program
    3. Using Sessions
      1. Starting a Session
      2. Ending a Session
      3. Setting a Timeout
      4. Session Security
    4. Questions
  17. 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. Incrementing, Decrementing, and Shorthand Assignment
      6. String Concatenation
      7. Escape Characters
    6. Variable Typing
    7. Functions
    8. Global Variables
    9. Local Variables
    10. The Document Object Model
      1. Another Use for the $ Symbol
      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
  18. 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
  19. 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
  20. 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
  21. 17. Using Asynchronous Communication
    1. What Is Asynchronous Communication?
    2. Using XMLHttpRequest
      1. Your First Asynchronous Program
      2. Using GET Instead of POST
      3. Sending XML Requests
      4. Using Frameworks for Asynchronous Communication
    3. Questions
  22. 18. Introduction to CSS
    1. Importing a Stylesheet
      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 Stylesheets
      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. Stylesheet Creators
      2. Stylesheet Methods
      3. Stylesheet Selectors
    9. The Difference Between div and span Elements
    10. Measurements
    11. Fonts and Typography
      1. font-family
      2. font-style
      3. font-size
      4. font-weight
    12. Managing Text Styles
      1. Decoration
      2. Spacing
      3. Alignment
      4. Transformation
      5. Indenting
    13. CSS Colors
      1. Short Color Strings
      2. Gradients
    14. Positioning Elements
      1. Absolute Positioning
      2. Relative Positioning
      3. Fixed Positioning
    15. Pseudoclasses
    16. Shorthand Rules
    17. The Box Model and Layout
      1. Setting Margins
      2. Applying Borders
      3. Adjusting Padding
      4. Object Contents
    18. Questions
  23. 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
      5. Multiple Backgrounds
    4. CSS3 Borders
      1. The border-color Property
      2. The border-radius Property
    5. Box Shadows
    6. Element Overflow
    7. Multicolumn Layout
    8. Colors and Opacity
      1. HSL Colors
      2. HSLA Colors
      3. RGB Colors
      4. RGBA Colors
      5. The opacity Property
    9. Text Effects
      1. The text-shadow Property
      2. The text-overflow Property
      3. The word-wrap Property
    10. Web Fonts
      1. Google Web Fonts
    11. Transformations
      1. 3D Transformations
    12. Transitions
      1. Properties to Transition
      2. Transition Duration
      3. Transition Delay
      4. Transition Timing
      5. Shorthand Syntax
    13. Questions
  24. 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. Canceling a Timeout
      3. Using setInterval
      4. Using Interrupts for Animation
    6. Questions
  25. 21. Introduction to jQuery
    1. Why jQuery?
    2. Including jQuery
      1. Choosing the Right Version
      2. Downloading
      3. Using a Content Delivery Network
      4. Customizing jQuery
    3. jQuery Syntax
      1. A Simple Example
      2. Avoiding Library Conflicts
    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 Asynchronous Communication
      1. Using the POST Method
      2. Using the GET Method
    15. Plug-ins
      1. jQuery User Interface
      2. Other Plug-ins
    16. Questions
  26. 22. Introduction to jQuery Mobile
    1. Including jQuery Mobile
    2. Getting Started
    3. Linking Pages
      1. Linking Synchronously
      2. Linking Within a Multipage Document
      3. Page Transitions
    4. Styling Buttons
    5. List Handling
      1. Filterable Lists
      2. List Dividers
    6. What Next?
    7. Questions
  27. 23. Introduction to HTML5
    1. The Canvas
    2. Geolocation
    3. Audio and Video
    4. Forms
    5. Local Storage
    6. Web Workers
    7. Microdata
    8. Questions
  28. 24. 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 putImageData Method
      3. 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. Questions
  29. 25. 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. Questions
  30. 26. 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. Drag and Drop
    7. Cross-Document Messaging
    8. Other HTML5 Tags
    9. Questions
  31. 27. Bringing It All Together
    1. Designing a Social Networking App
    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
  32. 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
    26. Chapter 26 Answers
  33. B. Online Resources
    1. PHP Resource Sites 
    2. MySQL Resource Sites
    3. JavaScript Resource Sites 
    4. CSS Resource Sites 
    5. HTML5 Resource Sites 
    6. Asynchronous Communication Resource Sites 
    7. Miscellaneous Resource Sites
  34. C. MySQL’s FULLTEXT Stopwords
  35. D. MySQL Functions
    1. String Functions
    2. Date Functions
    3. Time Functions
  36. E. jQuery Selectors, Objects, and Methods
    1. jQuery Selectors
    2. jQuery Objects
    3. jQuery Methods
  37. Index
  38. About the Author
  39. Colophon

Product information

  • Title: Learning PHP, MySQL & JavaScript, 5th Edition
  • Author(s): Robin Nixon
  • Release date: May 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491978917