Thinking outside the box, who hosts your site? Who else is on the server? Is someone able to reset magic_quotes_gpc for the whole server when they should only be altering their own?
The manual has code for checking magic quotes at runtime and branching accordingly. Best I can suggest is to include that routine and see what you get. Can't think of any reason why it is sporadic.
The other alternative is to clean the user input before submitting it. Use instr to search for ' or " etc.