Complete each lesson, attempt the exercise and compare with the worked answer.
Secure PHP and MySQL fundamentals
Understand input validation, parameterized queries and transactional records.
Open coding playground Developer toolsInput validation and escaping
Validate on the server even when the browser validates too. Treat every submitted field as untrusted. Escape output for the context where it appears. HTML escaping does not replace database parameterization.
Practice
What two steps protect a saved title shown in an HTML page?
Review answer
Validate the title length/type on input and HTML-escape it on output.
Prepared statements
Separate SQL syntax from user data using bound parameters. Do not interpolate a user-supplied identifier or value into a SQL query. Table and sort column names should come from a fixed allowlist.
Practice
Write a query to find one client by ID.
Review answer
$stmt = $pdo->prepare("SELECT * FROM clients WHERE id = ?"); $stmt->execute([$id]);
Transactions
A transaction makes several related database writes commit together or roll back together. Use it for invoice conversion, payments and stock or ledger postings. A unique source reference also prevents repeated operations from creating duplicates.
Practice
Why must a transfer debit and credit be in the same transaction?
Review answer
If either side fails, both must roll back; otherwise the accounts no longer reconcile.
