What is the purpose of the db_input function in the PHP code provided?

The purpose of the db_input function in the PHP code provided is to sanitize user input before inserting it into a database to prevent SQL injection attacks. This function helps to ensure that the data being inserted into the database is safe and does not contain any malicious code.

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

// Example usage:
$user_input = $_POST['user_input'];
$sanitized_input = db_input($user_input);
// Use $sanitized_input in your database query