SQL Injection
Question
What is SQL injection?
Hint
Use parameterized queries to prevent SQL injection.
Explanation
SQL injection is a security vulnerability where an attacker inserts malicious SQL code into a query via user input. Example: if a query is built by string concatenation like SELECT * FROM users WHERE name = user_input, an attacker could input a value like x; DROP TABLE users; -- to delete the table. Prevention: 1) Parameterized queries (prepared statements) — the most effective defense. 2) Input validation and sanitization. 3) Least-privilege database accounts. 4) ORM/query builders that parameterize automatically. 5) Stored procedures. Never build SQL queries by concatenating user input. SQL injection is a top security risk (OWASP Top 10).
Related Resources
Related Lessons
- DB Security
Learn security.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.