Learning PHP, MySQL & JavaScript, 7th 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 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, Node.js, 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

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. 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 HTML
      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. Node.js: An Alternative to Apache
    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. Transferring Files
    6. Using a Code Editor
    7. 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. Multiline Strings
      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 ? (or ternary) 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 Modularization
    7. Questions
  9. 5. PHP Functions and Objects
    1. PHP Functions
      1. Defining a Function
      2. Returning a Value
      3. Returning an Array
      4. Returning Global Variables
      5. 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. Static Methods
      11. Declaring Constants
      12. Property and Method Scope
      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. compact
      7. reset
      8. 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. 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 Privacy
    4. Transactions
      1. Transaction Storage Engines
      2. Using START TRANSACTION
      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 JavaScript Injection into HTML
    5. 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. 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. Outputting the results
      1. Using console.log
      2. Using alert
      3. Writing into Elements
      4. Using document.write
    2. JavaScript and HTML Text
      1. Using Scripts Within a Document Head
      2. Including JavaScript Files
      3. Debugging JavaScript Errors
    3. Using Comments
    4. Semicolons
    5. Variables
      1. String Variables
      2. Numeric Variables
      3. Arrays
    6. 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
    7. Variable Typing
    8. Functions
    9. Global Variables
    10. Local Variables
      1. Using let and const
    11. The Document Object Model
      1. Another Use for the $ Symbol
      2. Using the DOM
    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. Using onerror
    5. Using try...catch
    6. Conditionals
      1. The if Statement
      2. The else Statement
      3. The switch Statement
      4. The ? Operator
    7. Looping
      1. while Loops
      2. do...while Loops
      3. for Loops
      4. Breaking Out of a Loop
      5. The continue Statement
    8. Explicit Casting
    9. 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 Instance
      3. Accessing Objects
      4. Static methods and properties
      5. The legacy object-functions
    3. JavaScript Arrays
      1. Arrays
      2. Associative Arrays
      3. Multidimensional Arrays
      4. Using Array Methods
    4. Anonymous functions
      1. Arrow functions
    5. 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. Wildcard 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. The Fetch API
      1. Your First Asynchronous Program
      2. Cross-origin resource sharing (CORS)
      3. Using GET Instead of POST
      4. Sending JSON Requests
    2. Using XMLHttpRequest
    3. Using Frameworks for Asynchronous Communication
    4. Questions
  22. 18. Advanced CSS
    1. Attribute Selectors
      1. Matching Parts of Strings
    2. The box-sizing Property
    3. CSS 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. CSS 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. Flexbox
      1. Flex Items
      2. Flow Direction
      3. Justifying Content
      4. Aligning Items
      5. Aligning Content
      6. Resizing Items
      7. Flex Wrap
      8. Order
      9. Item Gaps
    14. CSS Grid
      1. Grid Container
      2. Grid Columns and Rows
      3. Grid flow
      4. Placing Grid Items
      5. Grid Gaps
      6. Alignment
    15. Questions
  23. 19. Accessing CSS from JavaScript
    1. Revisiting the getElementById Function
      1. The byId Function
      2. The style Function
      3. The by 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. Time-based events
      1. Using setTimeout
      2. Using setInterval
      3. Using Time-based Events for Animation
    6. Questions
  24. 20. Introduction to React
    1. What Is the Point of React Anyway?
    2. Accessing the React Files
      1. Including babel.js
    3. Our First React Project
      1. Using a Class Instead of a Function
      2. Pure and Impure Code: A Golden Rule
      3. Using Both a Class and a Function
      4. Props and Components
      5. The Differences Between Using a Class and a Function
    4. React State and Life Cycle
    5. Events in React
    6. Inline JSX Conditional Statements
    7. Using Lists and Keys
      1. Unique Keys
    8. Handling Forms
      1. Using Text Input
      2. Using textarea
      3. Using select
    9. React Native
      1. Taking React to the Next Level
    10. Questions
  25. 21. Introduction to Node.js
    1. Installing Node.js on Windows
    2. Installing Node.js on macOS
    3. Installing Node.js on Linux
    4. Getting Started With Node.js
      1. Building a Functioning Web Server
    5. Working With Modules
      1. In-built Modules
      2. Installing modules with npm
      3. Accessing MySQL
      4. Further Information
    6. Questions
  26. 22. Bringing It All Together
    1. Designing a Social Networking App
    2. Online Repository
    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
    17. Questions
  27. 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
  28. About the Author

Product information

  • Title: Learning PHP, MySQL & JavaScript, 7th Edition
  • Author(s): Robin Nixon
  • Release date: January 2025
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098152352