Assuming you have yet to identify exploits in PHP, everything should be escaped using prepared statements or mysql_real_escape_string before you allow anything to touch your database.
Data stored in $ _SESSION is not always clean. For multi-page forms, you can store user input in $ _SESSION until the last page when you write it all to the database. If you encounter any habit of thinking that $ _SESSION is "clean," you will end up in trouble.
You should absolutely get used to the fact that every piece of data in your system is dirty until you slip away from it. Please note: if you use dynamic table names, escaping will not help you. Never use table or column names in a query that has ever been near a user. Various shielding mechanisms do not escape the feedback signals. If you have a prepared request, say:
"SELECT * FROM `:aTable`;"
and aTable is a user, a user who enters something like
` WHERE id IN (DELETE FROM user);
potentially just deleted all your user entries.
Endophage May 18 '12 at 12:17 a.m. 2012-05-18 00:17
source share