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.
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?
First link · your turn
A website needs your typed text to get to its database. How does it send it there?
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
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?
What do many websites do with the text you type into a form?
What is SQL injection?
What does 'unchecked input' mean here?
What decides whether typed text stays as data?
Why can the database not separate the typed text from the command?
Where might an attacker type the input?
What is SQL injection used for, and what threat does each use pose?
Is SQL injection malware?
Is SQL injection password guessing?
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 postedMore OCR GCSE Computer Science topics
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.