pdo insert statement using datetime errors

A Gilani

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

ihsan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

insert database using pdo with datetime and auto increment

From Dev

PDO large insert statement

From Dev

Insert BIT value in MySQL using PDO Prepared Statement

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

PDO Insert SQL not executing with no errors

From Dev

INSERT not working with PDO prepared statement

From Dev

INSERT statement does not work with PDO

From Dev

Sql Insert Into Select statement PDO

From Dev

PHP insert statement returns no errors but does not insert

From Dev

Error in datetime with Oracle insert statement

From Dev

multiple PDO insert with single statement not working

From Dev

PDO Prepared statement insert 1 instead of string

From Dev

PDO insert statement with loop through $_POST array

From Dev

How to include SELECT statement into INSERT INTO with concatenation & pdo

From Dev

PHP PDO insert statement not going through

From Dev

PDO insert statement with loop through $_POST array

From Dev

PDO MYSQL insert statement not working (no error given)

From Dev

PDO integer converting integer on INSERT statement

From Dev

PHP PDO Insert Statement exceeding execution time

From Dev

Fetching inside if statement using PDO

From Dev

Using PDO and failing to insert a record

From Dev

Using mysql insert with implode in PDO

From Dev

Using PDO and failing to insert a record

From Dev

using INSERT for an xml statement

From Dev

using INSERT for an xml statement

From Dev

Using CqlOutputFormat for INSERT statement

From Dev

MySQL - Insert statement is correct, yet it still errors

From Dev

How to notice MySQL errors using PDO in PHP

Related Related

HotTag

Archive