Zend
200-710 · Question #118
Is the following code vulnerable to SQL Injection ($mysqli is an instance of the MySQLi class)? ``php $age = $mysqli->real_escape_string($_GET['age']); $name =…
The correct answer is D. Yes, because the $age variable is improperly escaped. See the full explanation below for the reasoning.
Security
Question
Is the following code vulnerable to SQL Injection ($mysqli is an instance of the MySQLi class)?
$age = $mysqli->real_escape_string($_GET['age']);
$name = $mysqli->real_escape_string($_GET['name']);
$query = "SELECT * FROM 'table' WHERE name LIKE '$name' AND age = $age";
$results = $mysqli->query($query);
Options
- ANo, the code is fully protected from SQL Injection.
- BYes, because the $name variable is improperly escaped.
- CYes, because the $name variable and the $age variable is improperly escaped.
- DYes, because the $age variable is improperly escaped.
- EYes, because you cannot prevent SQL Injection when using MySQLi
How the community answered
(34 responses)- A9% (3)
- B6% (2)
- C3% (1)
- D82% (28)
Topics
#SQL injection#real_escape_string#numeric parameters#unquoted variables
Community Discussion
No community discussion yet for this question.