### Instruction:
Develop a PHP script that connects to a MySQL database and performs CRUD operations on a table called "employees" with columns: id, first_name, last_name, email, and hire_date. Implement validation checks for user input and display appropriate error messages when necessary.


### Response:

Here's a simple PHP script that connects to a MySQL database and performs CRUD operations on the "employees" table. Please make sure to replace the placeholders with your actual database credentials.

```php
<?php

// Database connection
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to sanitize user input
function clean_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

// Create employee
function create_employee($first_name, $last_name, $email, $hire_date) {
    global $conn;

    // Validate user input
    if (empty($first_name) || empty($last_name) || empty($email) || empty($hire_date)) {
        echo "All fields are required.";
        return;
    }

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "Invalid email format.";
        return;
    }

    $sql = "INSERT INTO employees (first_name, last_name, email, hire_date)
            VALUES ('$first_name', '$last_name', '$email', '$hire_date')";

    if ($conn->query($sql) === TRUE) {
        echo "New employee created successfully.";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

// Read all employees
function read_employees() {
    global $conn;

    $sql = "SELECT id, first_name, last_name, email, hire_date FROM employees";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo "id: " . $row["id"]. " - Name: " . $row["first_name"]. " " . $row["last_name"]. " - Email: " . $row["email"]. " - Hire Date: " . $row["hire_date"]. "<br>";
        }
    } else {
        echo "No employees found.";
    }
}

// Update employee
function update_employee($id, $first_name, $last_name, $email, $hire_date) {
    global $conn;

    // Validate user input
    if (empty($id) || empty($first_name) || empty($last_name) || empty($email) || empty($hire_date)) {
        echo "All fields are required.";
        return;
    }

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "Invalid email format.";
        return;
    }

    $sql = "UPDATE employees SET first_name='$first_name', last_name='$last_name', email='$email', hire_date='$hire_date' WHERE id=$id";

    if ($conn->query($sql) === TRUE) {
        echo "Employee updated successfully.";
    } else {
        echo "Error updating employee: " . $conn->error;
    }
}

// Delete employee
function delete_employee($id) {
    global $conn;

    // Validate user input
    if (empty($id)) {
        echo "ID is required.";
        return;
    }

    $sql = "DELETE FROM employees WHERE id=$id";

    if ($conn->query($sql) === TRUE) {
        echo "Employee deleted successfully.";
    } else {
        echo "Error deleting employee: " . $conn->error;
    }
}

// Example usage
$first_name = clean_input($_POST["first_name"]);
$last_name = clean_input($_POST["last_name"]);
$email = clean_input($_POST["email"]);
$hire_date = clean_input($_POST["hire_date"]);

create_employee($first_name, $last_name, $email, $hire_date);
read_employees();
update_employee(1, $first_name, $last_name, $email, $hire_date);
delete_employee(2);

$conn->close();

?>
```

This script defines functions for creating, reading, updating, and deleting employees in the "employees" table. It also includes a function to sanitize user input and validate email addresses. You can call these functions with appropriate parameters to perform CRUD operations.

Please note that this example is not using prepared statements or any advanced security measures, so it's not recommended for production use without further improvements.