Thanks suarve, would you say that the validation is meant to replace mysqli_real_escape_string?
No.
You should use both, never trust any data coming into your code - whether it's from the request or the database.
Filter everything coming in the $_REQUEST global, and then filter everything going into the database - the database knows best how to escape special chars for itself, so use that functionality.