3 rows. That is what a search for a nonexistent email returned from a query built by pasting input into the SQL text. The same search through a prepared statement returned 0 rows. SQL injection happens when an app pastes user input into the SQL text, so the database parses part of that input as SQL. Keep the template fixed and pass values through the binding API.
What the parser sees
The database decides the structure of a query from the SQL text it parses. Concatenated input takes part in parsing: a quote closes your string literal, and whatever follows is read as SQL. A placeholder changes that: preparation compiles the template with a parameter slot where ? stood, and binding supplies the value to that slot. Bound strings remain values and cannot become SQL.
The fix in PHP
Unsafe code pastes the email straight into the SQL string.…