Closed Thread Icon

Topic awaiting preservation: MySQL NOW() (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12289" title="Pages that link to Topic awaiting preservation: MySQL NOW() (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: MySQL NOW() <span class="small">(Page 1 of 1)</span>\

 
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 06-28-2002 01:27

I want to have a field in my mysql table that holds either a 'datetime' or a 'timestamp' to keep track of the creation date of the data inserted. I didn't want to use the TIMESTAMP field type because unless you set it to itself in any subsequent updates to the row of data, it will automatically put in the current timestamp again.

I am therefore trying to use a DATETIME column type and trying to use the NOW() function to generate the current time in my insert statement (I'm using PHP).

code:
$sql = "INSERT INTO articles (title, description, date) values('$title', '$description', 'NOW()')";



When I check the field after the insert, I end up with all zeros in the date column.

I even tried assigning NOW() to a php variable and put that in my insert statement.

Is there something wrong with my syntax, or could there be something wrong with the way my local server is setup?

Thanks



-Butcher-

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-28-2002 01:51

Well the #1 thought without checking the NOW() function is that you have it escaped in single quotes.

In most languages single quotes make the next string literal. So you would be attempting to place the String "NOW()" into your data block. The now would then default to 0 since it is not valid input.

Maybe try simply unescaping it and it might work. Let me do some research and see if this is correct.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-28-2002 01:54

Yeah a little search brought up this little function:

$query = "INSERT INTO faq_strings (string,date) VALUES ('Hello',NOW())";

Which would make me change your statement to:

$sql = "INSERT INTO articles (title, description, date) values('$title', '$description', NOW())";

Which would prolly resolve the issue.

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 06-28-2002 02:07

Yea, that did the trick!

Thanks WarMage!


-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu