Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Insert Into datetime = NOW() is not working? [closed]

Tags:

php

mysql

pdo

I have the following code (php, mysql, pdo):

$stmt = $db->prepare("INSERT INTO agent_temp SET party=?, date = NOW()");
$stmt->execute(array($party));

when run, the party is insert correctly but the date is not inserting as it should (the system date and time at action). I have verified numerous times the field type for date is datetime.

Any ideas?

EDIT

To give actual data and the results returned:

assume the following:

$party = 'John';

the results return:

party      |      date    
-------------------------------------
John       |    0000-00-00 00:00:00

update:

When i run the following code directly within a mysql query browser, the insert works just as it should:

insert into agent_temp set party = 'John', date = NOW();

returning:

party      |      date    
-------------------------------------
John       |    2010-12-28 13:15:23

ANSWERED

Well, who is ready to kill me? I have no idea what caught it up but unfortunately the issue seemingly was due to an earlier version of the php script from my machine being cached and still running bad data. I refreshed, closed, and emptied my browser and now the script works. My apologies for making everybody's brains melt just a little.

like image 721
JM4 Avatar asked Dec 28 '10 19:12

JM4


1 Answers

How about:

$stmt = $db->prepare("INSERT INTO agent_temp SET party=?, date = ?");
$stmt->execute(array($_POST['party'], date("Y-m-d H:i:s")));
like image 170
Johandk Avatar answered Oct 06 '22 04:10

Johandk