I have noticed that I am not the only Moodle developer who gets confused by the addslashes/stripslashes issue. Even though this is not really a Moodle issue, let me summarize my understanding of the addslashes issue so that people can correct me:
1) any data that I want to write to a database must have single quotes ' , double quotes " and backslashes \ escaped with a backslash \. So for example O'Connor should be converted to O\'Connor before it is written to the database. This can be achieved with addslashes.
2) when the data is pulled from the database it comes out without the slashes. So it can't be written straight back. For example the function get_record produces an object that can not be immediately written back with update_record.
3) any data that is passed to a script via GET or POST already has slashes added. Thus such data should have these slashes removed before printing to the screen. The functions p() and s() do this automatically.
In view of point 2) above it would be convenient to have a function that adds slashes to all strings in an object. Does someone already have such a function?