it will help w/ the majority of them, but it cant fix sloppy coding on your part.
there is no single thing you can to to protect yourself. rather, you need to validate all user input before using it. when writing your code you need to think everything that will be sent to you is malacious, be paranoid, and be detail oriented.
but magic_quotes_gpc is probably already turned on(its the default) which means addslashes() was already run on the user input.
do some more reading on the subject, theres many examples you can look at so you get an idea what to watch out for.
another thing you should do is turn off display errors. errors are great to help you debug while your writing code, its also a great way for a hacker to figure out weaknesses in your code
dont display php errors on a production website
ini_set('display_errors', 0);
and dont do this stuff either on a live website. they dont need to know the real error
mysql_query($query) or die(mysql_error());
also, take a look at mysql_real_escape_string()