How can date input from a form be stored as a DATE type in a MySQL database using PHP?

When storing date input from a form as a DATE type in a MySQL database using PHP, you need to format the date input correctly before inserting it into the database. This can be done by using the PHP date() function to convert the date input into the MySQL date format (YYYY-MM-DD). Then, you can use a prepared statement to safely insert the formatted date into the database.

// Assuming $dateInput contains the date input from the form
$dateFormatted = date('Y-m-d', strtotime($dateInput));

// Prepare SQL statement
$stmt = $pdo->prepare("INSERT INTO table_name (date_column) VALUES (:date)");

// Bind parameters
$stmt->bindParam(':date', $dateFormatted);

// Execute the statement
$stmt->execute();