Recall & Review
beginner
What is SQL injection?
SQL injection is a security attack where a bad user adds harmful SQL code into a query to trick the database into doing things it shouldn't, like giving secret data or changing information.
Click to reveal answer
beginner
Why are unsafe SQL queries vulnerable to injection?
Unsafe queries mix user input directly into SQL commands without checking or cleaning it. This lets attackers add extra commands that the database runs, causing harm.
Click to reveal answer
beginner
Example of unsafe PHP SQL query using user input
In PHP, writing: <br>
$query = "SELECT * FROM users WHERE name = '" . $_GET['name'] . "'"; <br> is unsafe because the user can add SQL code inside the 'name' input.Click to reveal answer
intermediate
How does an attacker exploit an unsafe query?
The attacker types SQL code into input fields. For example, entering
' OR '1'='1' can change the query to always be true, showing all data instead of just one user.Click to reveal answer
beginner
What is a simple way to prevent SQL injection in PHP?
Use prepared statements with placeholders. This keeps user input separate from SQL code, so the database treats it only as data, not commands.
Click to reveal answer
What does SQL injection allow an attacker to do?
✗ Incorrect
SQL injection lets attackers add harmful SQL code via user input to manipulate the database.
Which PHP code is unsafe and vulnerable to SQL injection?
✗ Incorrect
Directly inserting user input into SQL strings without checks is unsafe.
What is a common sign of an SQL injection attack in a query?
✗ Incorrect
Attackers use SQL keywords in input to change query logic.
How do prepared statements help prevent SQL injection?
✗ Incorrect
Prepared statements keep user input separate so it can't change SQL commands.
Which of these is NOT a good practice to avoid SQL injection?
✗ Incorrect
Directly inserting user input without checks is unsafe and leads to injection.
Explain in your own words how SQL injection exploits unsafe queries.
Think about how mixing user input and SQL code can be dangerous.
You got /4 concepts.
Describe a simple PHP example of an unsafe SQL query and how it can be fixed.
Focus on how user input is included in the query.
You got /4 concepts.