What are the best practices for handling data from a reservation form in PHP?

When handling data from a reservation form in PHP, it is important to sanitize and validate the input to prevent SQL injection and other security vulnerabilities. It is also recommended to use prepared statements when interacting with a database to further protect against attacks. Additionally, storing sensitive information such as passwords securely using encryption techniques is crucial for data protection.

// Sanitize and validate input data from reservation form
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$check_in_date = date('Y-m-d', strtotime($_POST['check_in_date']));
$check_out_date = date('Y-m-d', strtotime($_POST['check_out_date']));

// Prepare SQL statement using prepared statements
$stmt = $pdo->prepare("INSERT INTO reservations (name, email, check_in_date, check_out_date) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $email, $check_in_date, $check_out_date]);

// Encrypt sensitive information before storing in the database
$encrypted_password = password_hash($_POST['password'], PASSWORD_DEFAULT);