Injection & Input · 8 min read · Intermediate
SQL Injection (SQLi) & Parameterized Queries
See how string concatenation turns user input into SQL commands, and eliminate SQLi permanently.
What you'll learn
- Recognize how `' OR '1'='1` alters query logic when strings are concatenated
- Use prepared statements / parameterized queries in Python, PHP, Node, and Java
- Use allow-lists for dynamic table or column names
Overview
See how string concatenation turns user input into SQL commands, and eliminate SQLi permanently.
Code Example
# VULNERABLE: attacker enters "' OR '1'='1' --"
# cursor.execute(f"SELECT * FROM users WHERE email = '{email}'")
# SAFE: parameterized query binds input strictly as data
cursor.execute(
"SELECT id, email, name FROM users WHERE email = ?",
(email,),
)
Key Takeaways
- Recognize how
' OR '1'='1alters query logic when strings are concatenated - Use prepared statements / parameterized queries in Python, PHP, Node, and Java
- Use allow-lists for dynamic table or column names
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why do parameterized queries stop SQL Injection?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.