← Blog
Web Security2026-04-089 min read

SQL Injection: How One Quote Character Breaks a Database

A single apostrophe in a login form can hand an attacker your entire database. Here's exactly how SQL injection works, why it still exists everywhere, and how to spot it.

In 1998, a researcher named Rain Forest Puppy published a paper describing a technique where you could manipulate a database query by injecting SQL syntax through user input. Over 25 years later, SQL injection is still the number one cause of data breaches involving web applications. That should tell you something.

This isn't a list of tools or a career tips post. This is a precise explanation of exactly what happens when you inject SQL — from the character you type to the database row that comes back.

How a login form actually works under the hood

When you type your username and password into a login form, the backend runs a database query something like this:

SELECT * FROM users
WHERE username = 'alice'
AND password = 'hunter2';

If that query returns a row, you're in. Simple enough. The problem is that most applications build that query by gluing your input directly into the SQL string:

query = "SELECT * FROM users WHERE username = '" + username + "' AND password = '" + password + "'";

The database has no idea where your input ends and the SQL begins. They're the same string.

What one quote character does

Type this as your username: admin'--

The query becomes:

SELECT * FROM users
WHERE username = 'admin'--' AND password = 'anything';

In SQL, -- is a comment. Everything after it is ignored. So the password check disappears. The query now just checks if a user named admin exists — and logs you in as them if it does.

No password required.

Going further: pulling data you shouldn't see

Authentication bypass is the obvious trick, but it's not the most dangerous. Once you can inject SQL, you can use UNION to append your own query and retrieve data from any table.

' UNION SELECT username, password, null FROM users--

That returns every username and password hash in the database alongside whatever the original query would have returned. From one input field.

With blind SQL injection — where the app doesn't show you query output — attackers use boolean conditions or time delays (SLEEP(5)) to extract data one bit at a time. Tools like sqlmap automate this entirely.

Why it's still everywhere

The actual fix

Parameterised queries (also called prepared statements). Your input is passed as a parameter separate from the SQL structure — the database treats it as data, not code, no matter what it contains.

// Vulnerable
query = "SELECT * FROM users WHERE username = '" + username + "'";

// Safe
stmt = db.prepare("SELECT * FROM users WHERE username = ?");
stmt.execute([username]);

The input admin'-- now searches literally for a user whose name is admin'--. The quote is data. It never touches the SQL parser.

Input sanitisation (escaping quotes) is not the fix. It's a layer that gets bypassed. Parameterised queries are the fix. If you're doing anything else, you have an SQLi vulnerability — you just haven't found the bypass yet.

How to find SQLi as a tester

The manual approach: add a single quote to every input field and look for database errors, unexpected behaviour, or a change in the response. A generic "internal server error" after a quote is a strong signal.

From there you determine the database type (MySQL, PostgreSQL, MSSQL — each has syntax differences), figure out the number of columns in the query using ORDER BY, then craft your UNION to extract what you need.

The automated approach is sqlmap. Point it at a URL with a parameter, let it run. It handles detection, exploitation, and extraction automatically.

// Practice this

Everything in this post has a live lab on hackr.gg. Spin up a vulnerable machine and exploit it yourself — no setup, no VPN, runs in your browser.

Open SQL Injection course
More posts
Web Security
XSS: From alert(1) to Session Hijack
11 min
Career
How to Start Bug Bounty With Zero Experience (Realistic Guide)
14 min
Web Security
IDOR: The Vulnerability That Keeps Making Headlines
8 min