Menu

What is SQL injection and how to prevent it
📰

What is SQL injection and how to prevent it

DEV Community: owasp·System Design Simple·4 days ago
#4jQiEmRn
#devtoowasp#devto#dev#email#string
Long article (542 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.