How can a PHP script handle user input errors, such as entering non-numeric characters for an ID?

When handling user input errors like entering non-numeric characters for an ID, you can use PHP functions like is_numeric() to validate the input before processing it. If the input is not numeric, you can display an error message to the user and prevent further execution of the script.

$id = $_POST['id'];

if (!is_numeric($id)) {
    echo "Error: ID must be a numeric value.";
    // handle the error, redirect or display a message to the user
} else {
    // continue processing the input
}