When you execute a SQL query, you have to clean your strings or users can execute malicious SQL on your website.
I usually just have a function escape_string(blah),
For maximum security, performance, and correctness use prepared statements. Here's how to do this with lots of examples in different languages, including PHP:
https://stackoverflow.com/questions/1973/what-is-the-best-way-to-avoid-sql-injection-attacks