Ten Questions Students Ask About SQL Injection

SQL injection comes up early in many courses, and it raises lots of questions. Here are ten we hear often from students, with short, honest answers. The questions are typical ones, not quotes from real people.

1. "What is SQL injection in one sentence?"

It is when someone types SQL code into an input box and your app accidentally runs it, because the app glued their text straight into a query.

2. "Can you show the mistake?"

# unsafe
sql = "SELECT * FROM users WHERE username = '" + username + "'"

If username contains a quote followed by extra SQL, the query changes meaning.

3. "What is the fix?"

Use placeholders, so the value is sent separately from the SQL:

# safe
conn.execute("SELECT * FROM users WHERE username = ?", (username,))

4. "Why do placeholders work?"

The database receives the SQL with a gap in it, and the value separately. It knows the value is data, never code, so nothing typed by a user can change the query's structure.

5. "Isn't checking the input enough?"

Checking input is good: an age should be a number, an email should look like an email. But it is not a replacement for placeholders. It is easy to miss a case, and some valid input, such as a surname with an apostrophe, contains characters that break glued-together SQL.

6. "Do ORMs protect me?"

For normal use, yes: ORMs and query builders use placeholders behind the scenes. The danger returns if you use their "raw SQL" features and glue strings there.

7. "What about table or column names from users?"

Placeholders only work for values, not for names of tables or columns. If a user picks a sort column, compare their choice with a fixed list:

allowed = {"name": "name", "date": "created_at"}
column = allowed.get(choice, "name")

Then use the safe column name from your list.

8. "Is SQL injection still a real problem today?"

Yes. Security organisations such as OWASP and MITRE still list injection among important weaknesses, mainly because of old code and unsafe examples. Our evidence review explains why.

9. "Can I practise attacking websites to learn?"

Only on systems you own or have clear permission to test, such as your own practice app or deliberately vulnerable training apps run on your own computer. Testing other people's websites without permission can be illegal and harmful.

10. "What else should I do besides placeholders?"

Quick summary

DoDon't
Use placeholders for every valueJoin strings to build SQL
Use allow-lists for namesTrust input because it "looks fine"
Practise on your own systemsTest sites without permission

See it in action in our hands-on tutorial: breaking and fixing a tiny login form.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.

No jobs, member profiles or expert services are listed or offered on this site; this page is general information only.