what does the mysql_real_escape_string do?
Read the PHP Manual on [man]mysql_real_escape_string/man. It helps to prevent SQL injection, but does not help to prevent malicious clientside code injection. For that you need to use strip_tags(), [man]htmlspecialchars/man or [man]htmlentities/man, depending on what is needed.
where strip_tags should be put
You would use it before inserting into the database. The potential problem with strip_tags() is that you could end up removing text that should not be removed.