mysqli_real_escape_string function requires the connection to your database.
$username = mysqli_real_escape_string($your_connection, $_POST['username']);
P.S.: Do not mix mysql_ functions* and mysqli_ functions*. Please use mysqli_* functions or PDO
because mysql_* functions are deprecated and will be removed in the future.