PHP Guestbook

Sin Zero

New Member
Messages
17
Reaction score
0
Points
0
I am trying to set up a guestbook code and have hit a problem. Nothing that stops it from functioning, though.

I have it setup to timestamp the entry and when I try to view the date and time an entry was posted, i get the same date (1969-12-31 19:00:00) which is obviously not the correct date.

The code for the timestamp function is:
PHP:
function getMysqlDatetime($timestamp) {
    return date("Y-m-d H:i:s", $timestamp);
}
and the insert function is:
PHP:
$query="INSERT INTO inu_guestbook VALUES('','" . getMySqlDatetime($timestamp) . "','$name','$rating','$message')";
Any suggestions?
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Can you show us the line where $timestamp is being defined? You should be setting it to the value of time() I believe.
 

Sin Zero

New Member
Messages
17
Reaction score
0
Points
0
I didn't define it. From what I understand from an article I read for setting up the timestamp, date("Y-m-d H:i:s", $timestamp);, it applies the date to $timestamp. I could be wrong since I am still pretty new at this. Is there a different way I could get a timestamp into the database?
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
If you didn't define it, I believe that php will conclude that you passed 0 as the second argument for date(), which is why you would get that other time. Try this instead:

PHP:
function getMysqlDatetime($timestamp = false) {
    return date("Y-m-d H:i:s", (!$timestamp && $timestamp !== 0 ? time() : $timestamp));
}

and

PHP:
$query="INSERT INTO inu_guestbook VALUES('','" . getMySqlDatetime() . "','$name','$rating','$message')";

The new definition for getMysqlDatetime() should return the current date/time when you don't pass it anything, and still allow you to format other times by passing them to it.
 
Top