Complete the code to safely select a user by ID using string concatenation.
SELECT * FROM users WHERE id = '[1]';
Using a fixed number like 42 avoids injection risks from user input.
Complete the code to demonstrate a vulnerable query using string concatenation.
query = "SELECT * FROM users WHERE username = '" + [1] + "';"
Using raw user input in string concatenation can lead to SQL injection.
Fix the error in the vulnerable query by replacing the blank with the correct safe method.
cursor.execute("SELECT * FROM users WHERE username = %s", ([1],))
Passing user input as a parameter prevents SQL injection.
Fill both blanks to create a safe query using parameterized inputs.
query = "SELECT * FROM users WHERE username = [1] AND password = [2]"
Using %s placeholders allows safe parameter substitution.
Fill all three blanks to safely execute a query with parameters.
cursor.execute("SELECT * FROM users WHERE username = [1] AND password = [2]", ([3], user_password))
Use %s placeholders and pass variables as parameters to avoid injection.
