Using String Concatenation to Build SQL Queries with User Input
PHP applications construct SQL queries by concatenating user-controlled input directly into SQL strings using PHP's string interpolation or concatenation operators. Developers write queries like $sql = "SELECT * FROM users WHERE id = $userId AND name = '$userName'"; or $sql = 'DELETE FROM posts WHERE id = ' . $_POST['post_id'];, embedding $_GET, $_POST, or $_REQUEST values directly into SQL command strings without any parameterization. This pattern treats SQL structure and user data as equivalent string content, allowing attackers to inject additional SQL syntax through user input. An attacker providing userId=1 OR 1=1-- or userName=' OR '1'='1 can manipulate the query logic to bypass authentication, extract unauthorized data, or execute administrative database operations. The PHP double-quote string interpolation feature that embeds variable values directly into strings ($variable within "string") makes this vulnerability particularly easy to introduce, as developers naturally write SQL queries as strings without considering the security boundary between trusted SQL syntax and untrusted user data.