You seem a bit mixed up there because you have 2 means of escaping data and none of filtering when the rule is FIEO Filter Input Escape Output
Filtering:
if YOU DECIDE that a "name" can only be upper and lower case letters, be between 2 and 50 characters long and can contain dashes and single quotes (') then you should either:
remove anything not matching your own definition example above (using regular expressions maybe)
OR
abort the operation
Depending on how kind you want to be to your user/potential cracker
filter_var() is also very useful in this scenario.
Escaping
You escape the data in readiness for the next environment the data is headed for;
If its to go into a database then you'd use your mysqli_real_escape_string(), if you are echoing to the screen in html then use htmlentities() and so on.
HTH