What DBMS are you using? Some may require '' instead of \' to escape single quotes.
Also, have you checked with singe/double quotes on smaller test data samples yet?
You dont need stripslashes() if magic_quotes_gpc is 1, so you probably only need to check for magic_quotes_gpc