How can the NOW() function in MySQL be utilized to fill a datetime field when creating a new record in PHP?

When creating a new record in PHP and inserting it into a MySQL database, you can utilize the NOW() function in MySQL to automatically fill a datetime field with the current date and time. This eliminates the need to manually input the datetime value in your PHP code.

// Connect to the database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Create a new record with the current datetime
$query = "INSERT INTO table_name (datetime_field) VALUES (NOW())";
$mysqli->query($query);

// Close the database connection
$mysqli->close();