I have a table with a field with type as TIMESTAMP
On my webpage i have two fields and the values being sent out are as follow.
$eDate = "Wed, 01 Apr 2015";
$eTime = "11:35 pm";
Using the following code i am trying to insert the values in the table
$str = trim($eDate) . " " . trim($eTime);
$eventDateTime = DateTime::createFromFormat("D\, d M Y g:i a", $str);
$conn = new PDO("mysql:host=$server_name;dbname=$db_name", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dateCreated = date("Y-m-d H:i:s");
//insert record
$statement = $conn->prepare("INSERT INTO events VALUES(DEFAULT, AES_ENCRYPT(:newEntryTitle,'$secretKey'), AES_ENCRYPT(:newEntry,'$secretKey'), :eventDate, :uid, :submission_date)");
$statement->bindParam(':newEntryTitle', $entity_elm2, PDO::PARAM_STR);
$statement->bindParam(':newEntry', $entity_elm1, PDO::PARAM_STR);
$statement->bindParam(':eventDate', $eventDateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR);
$statement->bindParam(':uid', $_SESSION["UserID"]);
$statement->bindParam(':submission_date', $dateCreated);
$statement->execute();
$last_id = $conn->lastInsertId();
I am getting an error
Call to a member function format() on a non-object
I have struggled with this for hours without any resolutions. Can someone help. Please
TIMESTAMP data type should accept timestamp. Change the line
$statement->bindParam(':eventDate', $eventDateTime->getTimestamp() ...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments