What is the purpose of the PHP function in the provided script?

The purpose of the PHP function in the provided script is to sanitize user input to prevent SQL injection attacks. This function ensures that any potentially harmful characters are escaped or removed from the input before it is used in a SQL query, thus protecting the database from malicious attacks.

function sanitize_input($input) {
    $input = trim($input);
    $input = stripslashes($input);
    $input = htmlspecialchars($input);
    return $input;
}