Skip to content
BENIBIX Learn

Input Validation vs Parameterized Query

People think checking what users type is enough to stop SQL injection, and it is not. Input validation turns away data that has the wrong shape, like letters in an age box. But a name can still hold a quote. A parameterized query keeps every value apart from the command, so even odd text stays data. You want both.

Development🔐 Security

Input Validation

Making sure what users send fits the rules. Then your code uses it.

Input validation checks outside data against rules before your code uses it. An age should be a whole number between 0 and 150. An email should look like an email. Anything that breaks the rules is turned away with a clear message. Checks in the browser are only for comfort; the server must check again, because anyone can skip the page.

Example
Lucy's sign-up form asks for an age. Someone sends minus 5 straight to her API, and the server answers 400 Bad Request instead of saving it.
Why it matters
Most attacks start with input the code did not expect. Checking it first stops whole kinds of bug.
Full entry
Development🔐 Security

Parameterized Query

A query with blank spots for the data. What a user types can never become a command.

A parameterized query keeps the SQL command and the user's data apart. You write the query with blank spots, like ? or $1. The data is sent on its own and fills those spots. The database never treats that data as part of the command. This is the main defence against SQL injection, and almost every database library supports it.

Example
Jack's login code used to glue the email into the SQL. He switches to a parameterized query, and a quote in an email is now just a quote.
Why it matters
It shuts SQL injection at the root. Filters and escaping only guess at what is dangerous.
Full entry

In one line

Input Validation
Making sure what users send fits the rules. Then your code uses it.
Parameterized Query
A query with blank spots for the data. What a user types can never become a command.