0%

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 the latest edition of this popular hands-on guide, you'll tackle dynamic web programming using the most recent versions of today's core technologies: PHP, MySQL, JavaScript, CSS, HTML5, jQuery, and the powerful React library.

Web designers will learn how to use these technologies together while picking up valuable web programming practices along the way, including how to optimize websites for mobile devices. 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 MySQL PDO 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 JavaScript with the React library
  • Use Ajax calls for background browser-server communication
  • Style your web pages by acquiring CSS skills
  • Implement HTML5 features, including geolocation, audio, video, and the canvas element
  • Reformat your websites into mobile web apps

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. Conventions Used in This Book
    5. Using Code Examples
    6. O’Reilly Online Learning
    7. How to Contact Us
    8. 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
    4. MariaDB: The MySQL Clone
    5. Using PHP
    6. Using MySQL
    7. Using JavaScript
    8. Using CSS
    9. And Then There’s HTML5
    10. The Apache Web Server
    11. Handling Mobile Devices
    12. About Open Source
    13. Bringing It All Together
    14. Questions
  6. 2. Setting Up a Development Server
    1. What Is a WAMP, MAMP, or LAMP?
    2. Installing AMPPS on Windows
    3. Testing the Installation
    4. Accessing the Document Root (Windows)
    5. Alternative WAMPs
    6. Installing AMPPS on macOS
    7. Accessing the Document Root (macOS)
    8. Installing a LAMP on Linux
    9. Working Remotely
    10. Logging In
    11. Using SFTP or FTPS
    12. Using a Code Editor
    13. Using an IDE
    14. Questions
  7. 3. Introduction to PHP
    1. Incorporating PHP Within HTML
    2. This Book’s Examples
    3. The Structure of PHP
    4. Using Comments
    5. Basic Syntax
    6. Variables
    7. Operators
    8. Variable Assignment
    9. Multiline Commands
    10. Variable Typing
    11. Constants
    12. Predefined Constants
    13. The Difference Between the echo and print Commands
    14. Functions
    15. Variable Scope
    16. Questions
  8. 4. Expressions and Control Flow in PHP
    1. Expressions
    2. TRUE or FALSE?
    3. Literals and Variables
    4. Operators
    5. Operator Precedence
    6. Associativity
    7. Relational Operators
    8. Conditionals
    9. The if Statement
    10. The else Statement
    11. The elseif Statement
    12. The switch Statement
    13. The ? (or ternary) Operator
    14. Looping
    15. while Loops
    16. do...while Loops
    17. for Loops
    18. Breaking Out of a Loop
    19. The continue Statement
    20. Implicit and Explicit Casting
    21. PHP Dynamic Linking
    22. Dynamic Linking in Action
    23. Questions
  9. 5. PHP Functions and Objects
    1. PHP Functions
    2. Defining a Function
    3. Returning a Value
    4. Returning an Array
    5. Passing Arguments by Reference
    6. Returning Global Variables
    7. Recap of Variable Scope
    8. Including and Requiring Files
    9. The include Statement
    10. Using include_once
    11. Using require and require_once
    12. PHP Version Compatibility
    13. PHP Objects
    14. Terminology
    15. Declaring a Class
    16. Creating an Object
    17. Accessing Objects
    18. Cloning Objects
    19. Constructors
    20. Destructors
    21. Writing Methods
    22. Declaring Properties
    23. Declaring Constants
    24. Property and Method Scope
    25. Static Methods
    26. Static Properties
    27. Inheritance
    28. Questions
  10. 6. PHP Arrays
    1. Basic Access
    2. Numerically Indexed Arrays
    3. Associative Arrays
    4. Assignment Using the array Keyword
    5. The foreach...as Loop
    6. Multidimensional Arrays
    7. Using Array Functions
    8. is_array
    9. count
    10. sort
    11. shuffle
    12. explode
    13. extract
    14. compact
    15. reset
    16. end
    17. Questions
  11. 7. Practical PHP
    1. Using printf
    2. Precision Setting
    3. String Padding
    4. Using sprintf
    5. Date and Time Functions
    6. Date Constants
    7. Using checkdate
    8. File Handling
    9. Checking Whether a File Exists
    10. Creating a File
    11. Reading from Files
    12. Copying Files
    13. Moving a File
    14. Deleting a File
    15. Updating Files
    16. Locking Files for Multiple Accesses
    17. Reading an Entire File
    18. Uploading Files
    19. System Calls
    20. XHTML or HTML5?
    21. Questions
  12. 8. Introduction to MySQL
    1. MySQL Basics
    2. Summary of Database Terms
    3. Accessing MySQL via the Command Line
    4. Starting the Command-Line Interface
    5. Using the Command-Line Interface
    6. MySQL Commands
    7. Data Types
    8. Indexes
    9. Creating an Index
    10. Querying a MySQL Database
    11. Joining Tables Together
    12. Using Logical Operators
    13. MySQL Functions
    14. Accessing MySQL via phpMyAdmin
    15. Questions
  13. 9. Mastering MySQL
    1. Database Design
    2. Primary Keys: The Keys to Relational Databases
    3. Normalization
    4. First Normal Form
    5. Second Normal Form
    6. Third Normal Form
    7. When Not to Use Normalization
    8. Relationships
    9. One-to-One
    10. One-to-Many
    11. Many-to-Many
    12. Databases and Anonymity
    13. Transactions
    14. Transaction Storage Engines
    15. Using BEGIN
    16. Using COMMIT
    17. Using ROLLBACK
    18. Using EXPLAIN
    19. Backing Up and Restoring
    20. Using mysqldump
    21. Creating a Backup File
    22. Restoring from a Backup File
    23. Dumping Data in CSV Format
    24. Planning Your Backups
    25. Questions
  14. 10. What’s New in PHP 8 and MySQL 8
    1. About This Chapter
    2. PHP 8
    3. Named Parameters
    4. Attributes
    5. Constructor Properties
    6. Just-In-Time Compilation
    7. Union Types
    8. Null-safe Operator
    9. match Expressions
    10. New Functions
    11. MySQL 8
    12. Updates to SQL
    13. JSON (JavaScript Object Notation)
    14. Geography Support
    15. Reliability
    16. Speed and Performance
    17. Management
    18. Security
    19. Questions
  15. 11. Accessing MySQL Using PHP
    1. Querying a MySQL Database with PHP
    2. The Process
    3. Creating a Login File
    4. Connecting to a MySQL Database
    5. A Practical Example
    6. The $_POST Array
    7. Deleting a Record
    8. Displaying the Form
    9. Querying the Database
    10. Running the Program
    11. Practical MySQL
    12. Creating a Table
    13. Describing a Table
    14. Dropping a Table
    15. Adding Data
    16. Retrieving Data
    17. Updating Data
    18. Deleting Data
    19. Using AUTO_INCREMENT
    20. Performing Additional Queries
    21. Preventing Hacking Attempts
    22. Steps You Can Take
    23. Using Placeholders
    24. Preventing JavaScript Injection into HTML
    25. Questions
  16. 12. Form Handling
    1. Building Forms
    2. Retrieving Submitted Data
    3. Default Values
    4. Input Types
    5. Sanitizing Input
    6. An Example Program
    7. HTML5 Enhancements
    8. The autocomplete Attribute
    9. The autofocus Attribute
    10. The placeholder Attribute
    11. The required Attribute
    12. Override Attributes
    13. The width and height Attributes
    14. The min and max Attributes
    15. The step Attribute
    16. The form Attribute
    17. The list Attribute
    18. The color Input Type
    19. The number and range Input Types
    20. Date and Time Pickers
    21. Questions
  17. 13. Cookies, Sessions, and Authentication
    1. Using Cookies in PHP
    2. Setting a Cookie
    3. Accessing a Cookie
    4. Destroying a Cookie
    5. HTTP Authentication
    6. Storing Usernames and Passwords
    7. An Example Program
    8. Using Sessions
    9. Starting a Session
    10. Ending a Session
    11. Setting a Timeout
    12. Session Security
    13. Questions
  18. 14. Exploring JavaScript
    1. JavaScript and HTML Text
    2. Using Scripts Within a Document Head
    3. Older and Nonstandard Browsers
    4. Including JavaScript Files
    5. Debugging JavaScript Errors
    6. Using Comments
    7. Semicolons
    8. Variables
    9. String Variables
    10. Numeric Variables
    11. Arrays
    12. Operators
    13. Arithmetic Operators
    14. Assignment Operators
    15. Comparison Operators
    16. Logical Operators
    17. Incrementing, Decrementing, and Shorthand Assignment
    18. String Concatenation
    19. Escape Characters
    20. Variable Typing
    21. Functions
    22. Global Variables
    23. Local Variables
    24. Using let and const
    25. The Document Object Model
    26. Another Use for the $ Symbol
    27. Using the DOM
    28. About document.write
    29. Using console.log
    30. Using alert
    31. Writing into Elements
    32. Using document.write
    33. Questions
  19. 15. Expressions and Control Flow in JavaScript
    1. Expressions
    2. Literals and Variables
    3. Operators
    4. Operator Precedence
    5. Associativity
    6. Relational Operators
    7. The with Statement
    8. Using onerror
    9. Using try...catch
    10. Conditionals
    11. The if Statement
    12. The else Statement
    13. The switch Statement
    14. The ? Operator
    15. Looping
    16. while Loops
    17. do...while Loops
    18. for Loops
    19. Breaking Out of a Loop
    20. The continue Statement
    21. Explicit Casting
    22. Questions
  20. 16. JavaScript Functions, Objects, and Arrays
    1. JavaScript Functions
    2. Defining a Function
    3. Returning a Value
    4. Returning an Array
    5. JavaScript Objects
    6. Declaring a Class
    7. Creating an Object
    8. Accessing Objects
    9. The prototype Keyword
    10. JavaScript Arrays
    11. Numeric Arrays
    12. Associative Arrays
    13. Multidimensional Arrays
    14. Using Array Methods
    15. Questions
  21. 17. JavaScript and PHP Validation and Error Handling
    1. Validating User Input with JavaScript
    2. The validate.html Document (Part 1)
    3. The validate.html Document (Part 2)
    4. Regular Expressions
    5. Matching Through Metacharacters
    6. Fuzzy Character Matching
    7. Grouping Through Parentheses
    8. Character Classes
    9. Indicating a Range
    10. Negation
    11. Some More Complicated Examples
    12. Summary of Metacharacters
    13. General Modifiers
    14. Using Regular Expressions in JavaScript
    15. Using Regular Expressions in PHP
    16. Redisplaying a Form After PHP Validation
    17. Questions
  22. 18. Using Asynchronous Communication
    1. What Is Asynchronous Communication?
    2. Using XMLHttpRequest
    3. Your First Asynchronous Program
    4. Using GET Instead of POST
    5. Sending XML Requests
    6. Using Frameworks for Asynchronous Communication
    7. Questions
  23. 19. Introduction to CSS
    1. Importing a Stylesheet
    2. Importing CSS from Within HTML
    3. Embedded Style Settings
    4. Using IDs
    5. Using Classes
    6. Using Semicolons
    7. CSS Rules
    8. Multiple Assignments
    9. Using Comments
    10. Style Types
    11. Default Styles
    12. User Styles
    13. External Stylesheets
    14. Internal Styles
    15. Inline Styles
    16. CSS Selectors
    17. The Type Selector
    18. The Descendant Selector
    19. The Child Selector
    20. The ID Selector
    21. The Class Selector
    22. The Attribute Selector
    23. The Universal Selector
    24. Selecting by Group
    25. The CSS Cascade
    26. Stylesheet Creators
    27. Stylesheet Methods
    28. Stylesheet Selectors
    29. The Difference Between div and span Elements
    30. Measurements
    31. Fonts and Typography
    32. font-family
    33. font-style
    34. font-size
    35. font-weight
    36. Managing Text Styles
    37. Decoration
    38. Spacing
    39. Alignment
    40. Transformation
    41. Indenting
    42. CSS Colors
    43. Short Color Strings
    44. Gradients
    45. Positioning Elements
    46. Absolute Positioning
    47. Relative Positioning
    48. Fixed Positioning
    49. Pseudoclasses
    50. Shorthand Rules
    51. The Box Model and Layout
    52. Setting Margins
    53. Applying Borders
    54. Adjusting Padding
    55. Object Contents
    56. Questions
  24. 20. Advanced CSS with CSS3
    1. Attribute Selectors
    2. Matching Parts of Strings
    3. The box-sizing Property
    4. CSS3 Backgrounds
    5. The background-clip Property
    6. The background-origin Property
    7. The background-size Property
    8. Using the auto Value
    9. Multiple Backgrounds
    10. CSS3 Borders
    11. The border-color Property
    12. The border-radius Property
    13. Box Shadows
    14. Element Overflow
    15. Multicolumn Layout
    16. Colors and Opacity
    17. HSL Colors
    18. HSLA Colors
    19. RGB Colors
    20. RGBA Colors
    21. The opacity Property
    22. Text Effects
    23. The text-shadow Property
    24. The text-overflow Property
    25. The word-wrap Property
    26. Web Fonts
    27. Google Web Fonts
    28. Transformations
    29. 3D Transformations
    30. Transitions
    31. Properties to Transition
    32. Transition Duration
    33. Transition Delay
    34. Transition Timing
    35. Shorthand Syntax
    36. Questions
  25. 21. Accessing CSS from JavaScript
    1. Revisiting the getElementById Function
    2. The O Function
    3. The S Function
    4. The C Function
    5. Including the Functions
    6. Accessing CSS Properties from JavaScript
    7. Some Common Properties
    8. Other Properties
    9. Inline JavaScript
    10. The this Keyword
    11. Attaching Events to Objects in a Script
    12. Attaching to Other Events
    13. Adding New Elements
    14. Removing Elements
    15. Alternatives to Adding and Removing Elements
    16. Using Interrupts
    17. Using setTimeout
    18. Canceling a Timeout
    19. Using setInterval
    20. Using Interrupts for Animation
    21. Questions
  26. 22. Introduction to jQuery
    1. Why jQuery?
    2. Including jQuery
    3. Choosing the Right Version
    4. Downloading
    5. Using a Content Delivery Network
    6. Customizing jQuery
    7. jQuery Syntax
    8. A Simple Example
    9. Avoiding Library Conflicts
    10. Selectors
    11. The css Method
    12. The Element Selector
    13. The ID Selector
    14. The Class Selector
    15. Combining Selectors
    16. Handling Events
    17. Waiting Until the Document Is Ready
    18. Event Functions and Properties
    19. The blur and focus Events
    20. The this Keyword
    21. The click and dblclick Events
    22. The keypress Event
    23. Considerate Programming
    24. The mousemove Event
    25. Other Mouse Events
    26. Alternative Mouse Methods
    27. The submit Event
    28. Special Effects
    29. Hiding and Showing
    30. The toggle Method
    31. Fading In and Out
    32. Sliding Elements Up and Down
    33. Animations
    34. Stopping Animations
    35. Manipulating the DOM
    36. The Difference Between the text and html Methods
    37. The val and attr Methods
    38. Adding and Removing Elements
    39. Dynamically Applying Classes
    40. Modifying Dimensions
    41. The width and height Methods
    42. The innerWidth and innerHeight Methods
    43. The outerWidth and outerHeight Methods
    44. DOM Traversal
    45. Parent Elements
    46. Child Elements
    47. Sibling Elements
    48. Selecting the Next and Previous Elements
    49. Traversing jQuery Selections
    50. The is Method
    51. Using jQuery Without Selectors
    52. The $.each Method
    53. The $.map Method
    54. Using Asynchronous Communication
    55. Using the POST Method
    56. Using the GET Method
    57. Plug-ins
    58. jQuery User Interface
    59. Other Plug-ins
    60. Questions
  27. 23. Introduction to jQuery Mobile
    1. Including jQuery Mobile
    2. Getting Started
    3. Linking Pages
    4. Linking Synchronously
    5. Linking Within a Multipage Document
    6. Page Transitions
    7. Styling Buttons
    8. List Handling
    9. Filterable Lists
    10. List Dividers
    11. What Next?
    12. Questions
  28. 24. Introduction to React
    1. What Is the Point of React Anyway?
    2. Accessing the React Files
    3. Including babel.js
    4. Our First React Project
    5. Using a Function Instead of a Class
    6. Pure and Impure Code: A Golden Rule
    7. Using Both a Class and a Function
    8. Props and Components
    9. The Differences Between Using a Class and a Function
    10. React State and Life Cycle
    11. Using Hooks (if You Use Node.js)
    12. Events in React
    13. Inline JSX Conditional Statements
    14. Using Lists and Keys
    15. Unique Keys
    16. Handling Forms
    17. Using Text Input
    18. Using textarea
    19. Using select
    20. React Native
    21. Creating React Native Apps
    22. Further Reading
    23. Taking React to the Next Level
    24. Questions
  29. 25. Introduction to HTML5
    1. The Canvas
    2. Geolocation
    3. Audio and Video
    4. Forms
    5. Local Storage
    6. Web Workers
    7. Questions
  30. 26. The HTML5 Canvas
    1. Creating and Accessing a Canvas
    2. The toDataURL Function
    3. Specifying an Image Type
    4. The fillRect Method
    5. The clearRect Method
    6. The strokeRect Method
    7. Combining These Commands
    8. The createLinearGradient Method
    9. The addColorStop Method in Detail
    10. The createRadialGradient Method
    11. Using Patterns for Fills
    12. Writing Text to the Canvas
    13. The strokeText Method
    14. The textBaseline Property
    15. The font Property
    16. The textAlign Property
    17. The fillText Method
    18. The measureText Method
    19. Drawing Lines
    20. The lineWidth Property
    21. The lineCap and lineJoin Properties
    22. The miterLimit Property
    23. Using Paths
    24. The moveTo and lineTo Methods
    25. The stroke Method
    26. The rect Method
    27. Filling Areas
    28. The clip Method
    29. The isPointInPath Method
    30. Working with Curves
    31. The arc Method
    32. The arcTo Method
    33. The quadraticCurveTo Method
    34. The bezierCurveTo Method
    35. Manipulating Images
    36. The drawImage Method
    37. Resizing an Image
    38. Selecting an Image Area
    39. Copying from a Canvas
    40. Adding Shadows
    41. Editing at the Pixel Level
    42. The getImageData Method
    43. The putImageData Method
    44. The createImageData Method
    45. Advanced Graphical Effects
    46. The globalCompositeOperation Property
    47. The globalAlpha Property
    48. Transformations
    49. The scale Method
    50. The save and restore Methods
    51. The rotate Method
    52. The translate Method
    53. The transform Method
    54. The setTransform Method
    55. Questions
  31. 27. HTML5 Audio and Video
    1. About Codecs
    2. The <audio> Element
    3. The <video> Element
    4. The Video Codecs
    5. Questions
  32. 28. Other HTML5 Features
    1. Geolocation and the GPS Service
    2. Other Location Methods
    3. Geolocation and HTML5
    4. Local Storage
    5. Using Local Storage
    6. The localStorage Object
    7. Web Workers
    8. Drag and Drop
    9. Cross-Document Messaging
    10. Other HTML5 Tags
    11. Questions
  33. 29. Bringing It All Together
    1. Designing a Social Networking App
    2. On the Website
    3. functions.php
    4. The Functions
    5. header.php
    6. setup.php
    7. index.php
    8. signup.php
    9. Checking for Username Availability
    10. Logging In
    11. checkuser.php
    12. login.php
    13. profile.php
    14. Adding the “About Me” Text
    15. Adding a Profile Image
    16. Processing the Image
    17. Displaying the Current Profile
    18. members.php
    19. Viewing a User’s Profile
    20. Adding and Dropping Friends
    21. Listing All Members
    22. friends.php
    23. messages.php
    24. logout.php
    25. styles.css
    26. javascript.js
    27. Questions
  34. 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
    27. Chapter 27 Answers
    28. Chapter 28 Answers
    29. Chapter 29 Answers
  35. Index
  36. About the Author
  37. Colophon
3.142.119.241