Potresti usare addslashes() oppure mysql_escape_string().

Quando andrai ad estrarre i dati, per eliminare gli slash aggiunti, userai stripslashes()