GCSE · Computer Science · OCR · Spec J277

SQL injection

One ordinary box on a website, two very different endings. The difference is whether the application checked what you typed.

Follow the typed text

Same box, two routes

Someone types into a login box or a search box on a website. Follow their text: pick a route at each fork and see where it ends up.

What the application does with the typed text → What an attacker uses the unchecked route for

  • The application takes the typed text and passes it to the database behind the site. It does this with SQL, the language for searching, retrieving and changing the data in a database.

5 ends to explore.

On Someone types text into a form box on a website. 2 branches to choose from.

The tree shows the idea at concept level. It does not show an attack, and these four purposes are the ones this lesson covers.

Why does it work?

?

Reason it through

Why can text typed into a form end up working as part of a database command?

Link 1 of 4

First link · your turn

A website needs your typed text to get to its database. How does it send it there?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

Which idea do you hold?

What kind of attack is it?

SQL injection sits on a list of forms of attack on computer systems and networks, next to things like malware and password guessing. It is easy to blur them together.

Which idea is closest to what you think SQL injection is? Pick one, then say how sure you are.
How sure are you?

Your turn to write

Describe it in your own words

A music shop's website has a search box. Whatever a visitor types is passed to the shop's database using SQL. Describe how SQL injection could be used against the search box, and state one threat it poses to the shop. [3 marks]

0 words · your answer stays on this page and is not sent anywhere.

UK note

OCR GCSE Computer Science (J277): SQL injection is named in section 1.4.1, Threats to computer systems and networks, which is assessed in Paper 1 (Computer systems). Computer Science is not tiered, so this is for everyone.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

How one form box can lead to two very different outcomes, and what an attacker is after.

What you need to know

  • A database holds data, and SQL (Structured Query Language) is the language used to search, retrieve and change it.
  • Many websites and apps use SQL behind the scenes to pass what you type into a form to their database.
  • Have a goYour mate swears a school website's search box only searches the page you're looking at. Where does the typed text really go?

    To a database behind the site, passed on using SQL.

    Many websites and apps use SQL to pass what a user types into a form to their database. The page is only the front door.

  • An application that builds its database command directly from what was typed, without checking it, is using unchecked input.
  • Then the database can treat typed text as part of the command, instead of as ordinary data.
  • Have a goPredict: what is the one thing a careless application skips that lets typed text be treated as part of its command?

    Checking the input before it builds the command.

    The risk comes from building the command directly from unchecked input, not from the box itself or from typing in it.

  • That is SQL injection: an attack where input typed into a form field, such as a login or search box, becomes part of the SQL command.
  • Attackers use it to gain unauthorised access to a database, for example to get round a login, or to view, steal, change or delete data.
  • Have a goA classmate says: 'To beat a login, an attacker using SQL injection still has to guess the password.' What does that get wrong?

    It can get round the login, so no guessing is needed.

    SQL injection is not password guessing. The typed input is treated as part of the command, which can get round a login rather than pass its check.

  • The threats are stolen or exposed data (such as personal or account details), unauthorised changes or deletion, and unauthorised access to accounts or systems.
  • It is not malware and it is not password guessing: it exploits how the application builds its command.

The big picture

SQL is the language used to search, retrieve and change data in a database, and many websites use it to pass typed form input to their database. SQL injection happens when an application builds its command directly from unchecked input, so the database treats what an attacker typed into a form field as part of the command instead of ordinary data. Attackers use it to gain unauthorised access: to get round a login, or to view, steal, change or delete data. It is not malware and it is not password guessing.

Key points

1SQL is the language used to search, retrieve and change data in a database, and many websites use it to pass typed form input to their database.
2SQL injection happens when an application builds its database command directly from unchecked input.
3The database then treats what an attacker typed into a form field (such as a login or search box) as part of the SQL command instead of as ordinary data.
4Attackers use it to gain unauthorised access to a database: to get round a login, or to view, steal, change or delete data.
5It threatens stored data (such as personal or account details) through theft, exposure, unauthorised changes or deletion, and it threatens access to accounts or systems.
6It is not malware and it is not password guessing.

Worked example

Problem

Practice question: A school website has a 'find a club' search box. Its application builds the database command directly from whatever is typed, with no check. A pupil says: 'A search box only ever holds data, so the worst that can happen is a wrong search result.' Explain why the pupil is wrong.

⚠ Watch out

Calling SQL injection a virus or a way of guessing passwords. It installs nothing and it guesses nothing: it exploits how an application builds its database command from unchecked input. Say 'unchecked input' and 'treated as part of the command'.

🧠

Memory hook

Check it, or it becomes command: typed text the application never checks can stop being data and start giving orders.

✓

Check yourself

Cover the page. Explain how typed text can end up as part of a database command, then name one use an attacker has for it and its threat.

Flashcards

(10)
What is SQL?
Structured Query Language: the language used to search, retrieve and change data held in a database.
What do many websites do with the text you type into a form?
They use SQL to pass it to the database behind the scenes.
What is SQL injection?
An attack where input typed into a form field is treated by the database as part of the SQL command instead of as ordinary data.
What does 'unchecked input' mean here?
Typed text that the application uses to build its database command without checking it first.
What decides whether typed text stays as data?
Whether the application builds its command directly from unchecked input.
Why can the database not separate the typed text from the command?
The application has joined them into one command, so the database has no way to tell where the programmer's part ends and the typed part begins.
Where might an attacker type the input?
Into a form field, such as a login box or a search box.
What is SQL injection used for, and what threat does each use pose?
Getting round a login: unauthorised access to accounts or systems. Viewing or stealing data: stored data is stolen or exposed. Changing or deleting data: unauthorised changes or loss of data.
Is SQL injection malware?
No. Nothing has to be installed. It exploits how an application builds its database command from unchecked input.
Is SQL injection password guessing?
No. It does not try lots of passwords. The typed input is treated as part of the command, which can get round a login.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 18 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.