Zend
200-550 · Question #94
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'])…
The correct answer is D. Yes, because the $age variable is improperly escaped. See the full explanation below for the reasoning.
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
(31 responses)- A10% (3)
- B6% (2)
- C3% (1)
- D77% (24)
- E3% (1)
Community Discussion
No community discussion yet for this question.