How can the PHP script be improved to handle incorrect user input more effectively?

The PHP script can be improved to handle incorrect user input more effectively by implementing input validation. This can be done by checking the user input against certain criteria (such as data type, length, format) before processing it. If the input does not meet the specified criteria, an error message can be displayed to the user prompting them to provide valid input.

<?php

// Check if the user input is a valid number
if (!is_numeric($_POST['number'])) {
    echo "Error: Please enter a valid number.";
} else {
    // Process the user input
    $number = $_POST['number'];
    echo "You entered: " . $number;
}

?>