Read the OWASP SQL Injection Prevention Cheat Sheet and any related materials of interest to you.