Is this all to stop SQL injection in Drupal?
db_query('INSERT INTO {tablename} (field1, field2) VALUES ("%s", "%s")', $field1, $field2);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Is your question “Is this all I need to do to stop SQL injection in Drupal?”
The answer is “Almost, but not quite.”
Single quotes are more standard for quoting values in SQL.
Alternately, if you’ve defined tablename table via hook_schema, you can use drupal_write_record instead, as the other answer states. The advantage of drupal_write_record is that you don’t have to deal with any sql, you just do this: