One can use the php function mysql_escape_string() to construct mysql queries that contain special characters like quotes, backslashes, etc. This function handles sinqle quotes well but does not seem to handle double quotes appropriately.

I got better results with the addslashes() function that handles both single and double quotes very well.