php – PDO Exception – Invalid DateTime Format 1292-ThrowExceptions

Exception or error:

Getting the “Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292” error with my PHP website.

I am formatting the date, so not sure why it throws the error. Have checked some answers on here about this issue, but none seem to solve this.

Thanks in advance! 🙂

Code:

<?php
include('../includes/conn.inc.php');
include('../includes/functions.inc.php');
$sEventName = safeString($_POST['eventName']);
$sEventDescription = safeString($_POST['eventDescription']);
$sEventDate = $_POST['eventDate'];
$sEventDate = date('Y-m-d H:i:s');
//$eDate = strtotime($_POST['eventDate']);;
//$date=date("d/m/Y H:i:s", $eDate);
$sEventLocation = safeString($_POST['location']);
$sEventCountry = safeString($_POST['country']);
$sNumberTickets = safeInt($_POST['numberTickets']);
$sTicketPrice = safeString($_POST['cost']);

$sql = "INSERT INTO events(eventName, eventDescription,eventDate,numberTickets,location,country,cost)
VALUES (':eventName', ':eventDescription',':eventDate',':numberTickets',':location',':country',':cost')";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':eventName',$sEventName, PDO::PARAM_STR);
$stmt->bindParam(':eventDescription',$sEventDescription,PDO::PARAM_STR);
$stmt->bindParam(':eventDate',$sEventDate,PDO::PARAM_STR);
$stmt->bindParam(':location',$sEventLocation,PDO::PARAM_STR);
$stmt->bindParam(':numberTickets',$sNumberTickets,PDO::PARAM_INT);
$stmt->bindParam(':country',$sEventCountry,PDO::PARAM_STR);
$stmt->bindParam(':cost', $sTicketPrice,PDO::PARAM_STR);




$stmt->execute();
// redirect browser
header("Location: ../../admin.php");

?>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *