nerdexam
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)
  • A
    10% (3)
  • B
    6% (2)
  • C
    3% (1)
  • D
    77% (24)
  • E
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 200-550 Practice