What is the correct syntax for inserting current date and time values into a MySQL table using PHP?

When inserting current date and time values into a MySQL table using PHP, you can use the NOW() function in your SQL query. This function will automatically insert the current date and time into the specified column. Make sure to properly format your SQL query and handle any errors that may occur during the insertion process.

<?php

// Establish a connection to the MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check if the connection was successful
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Insert current date and time into a table
$sql = "INSERT INTO table_name (date_time_column) VALUES (NOW())";

if (mysqli_query($connection, $sql)) {
    echo "Record inserted successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($connection);
}

// Close the database connection
mysqli_close($connection);

?>