I have spent the afternoon trying various solutions but despite numerous questions on 'SO', I have not been able to resolve this issue.
My PHP code is below where I want to INSERT dates into a mySQL table, the table only has 3 columns as per screenshot.
The dates arrive in php already formatted as 2020-10-03
. My understanding was this would be sufficiently correct to send them directly to mySQL, however I have tried to convert them in different ways, but I still receive the following error:
include(dirname(__DIR__).'/php/dbConnection.php');
ini_set('display_errors', 'On');
error_reporting(E_ALL);
//values passed from ajax
// $id = $_POST['staffID'];
// $fromDate = $_POST['startDate'];
// $endDate = $_POST['endDate'];
//for testing > This Fails
$id = '22';
$fromDate = DateTime::createFromFormat('d-m-Y', '10-06-2020')->format('Y-m-d');
$endDate = DateTime::createFromFormat('d-m-Y', '12-06-2020')->format('Y-m-d');
//for testing > This Fails
//$id = '22';
//$fromDate = '2020-06-30';
//$endDate = '2020-07-30';
$data = array(); // array to pass back data
$stmt = $conn->prepare("INSERT INTO vacation (id, from_date, to_date)
VALUES ($id, $fromDate, $endDate)");
$stmt->execute();
$data['success'] = true;
$data['message'] = 'Success!';
echo json_encode($data);
mysqli_close($conn);
appreciate any guidance on where I am going wrong and how I need to interpret this error message.
Cheers