What are the best practices for data validation and normalization in PHP when dealing with customer information to prevent duplicate entries?

When dealing with customer information in PHP, it is important to implement data validation and normalization to prevent duplicate entries. This can be achieved by validating input data to ensure it meets the required format and by normalizing data to a consistent format before storing it in the database. Using functions like filter_var() for validation and strtolower() for normalization can help maintain data integrity and prevent duplicates.

// Data validation and normalization example
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_NUMBER_INT);

$name = strtolower($name); // Normalize name to lowercase

// Check for duplicate entries before inserting into the database
// Implement your duplicate check logic here