All the other answers in this thread generally suggest two main ways of tackling SQL injection; blacklisting and whitelisting.
As you most likely know, blacklisting is having a list of characters that should be banned, and whitelisting is having a list of characters that should be allowed. Whitelisting is generally more secure because one may have to keep updating a blacklist, while a whitelist would change much less frequently, if at all.
One simple example of whitelisting, already given in this thread, is casting variables to integers, assuming the variable should be an integer. Dangerous, and not dangerous, strings would be caught.
What I suggest is writing your own code, perhaps including regular expressions, that checks the data with a whitelist. Though, input that could be filled with a very diverse array of characters might make a blacklist somewhat easier.
In summary, whitelist when you can, and blacklist when whitelisting would be too complicated. Functions, like mysql_real_escape_string ()
, and other things that were mentioned in other answers, can help you with the specifics.