How can the syntax error in the provided PHP code snippet be fixed to properly use mysql_real_escape_string?

The issue with the provided PHP code snippet is that `mysql_real_escape_string` is deprecated and should not be used. Instead, `mysqli_real_escape_string` should be used to properly escape strings to prevent SQL injection attacks. To fix the syntax error, simply replace `mysql_real_escape_string` with `mysqli_real_escape_string` in the code snippet.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Escape user input for security
$username = mysqli_real_escape_string($connection, $_POST['username']);
$password = mysqli_real_escape_string($connection, $_POST['password']);
$email = mysqli_real_escape_string($connection, $_POST['email']);

// Rest of the code