Skip to content
BENIBIX Learn

SQL Injection

Development🔐 SecurityAttacks

Also known as SQLi, SQL Injection Attack

An attack that hides database commands in a form. The app then runs them.

Think of it like

Think of it like a form that asks your name. You write your name, then add: and open the safe.

Example

Jack's search box builds its query by joining strings. Someone types a quote and a DROP TABLE command, and his products table is gone.

Why it matters

It is one of the oldest web attacks and still among the most damaging. One open query can leak every row.

Definition

SQL injection hides database commands in a form, so the app runs them. It happens when code glues user input straight into an SQL query. Typing ' OR '1'='1 into a login box can make the query true for every user. Attackers can then read, change or delete the whole database. The fix is a query with placeholders. It keeps input as data, never as code.

Example code

sql
SELECT * FROM users
WHERE name = '' OR '1'='1';
The typed text turned the check into one that is always true.

Common mistake

Trying to clean input by taking out quotes. Use queries with placeholders instead; they fix it for good.

Key takeaways

  1. 1
    Input becomes code. That is the flaw.
  2. 2
    The whole database. Is at risk.
  3. 3
    Placeholders. Keep input as data.