Do not use mysql_real_escape_string() It's a deprecated function and provides you with essentially no protection if someone actually wants to hack you.
Search up a tutorial on MySQLi or (preferably) PDO. Query parameterization and prepared statements are the way to go.
It's my job to help the next generation, and set a good example for them. And for that I'll gladly lay down my life.