Forum Moderators: coopster

Message Too Old, No Replies

automatic date in guestbook

         

raulwg

6:13 pm on May 9, 2003 (gmt 0)

10+ Year Member



I'm building up a guestbook...so far it's possible for people to leave their name email and message...that works fine. I made in php with a connection to a db in mysql. Now I want to expand it with an automatic notification of when (time & date) they posted it. SO that people don't have influence on that, of course...Then of course it's also possible to sort them by date...(that is not the problem).

Where should I look? Any recommandation? Does it have to do with timestamp in the db?
Thanx in advance. Raul

jatar_k

6:23 pm on May 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can use NOW() in your insert

Date and Time Functions [mysql.com]

NOW()
SYSDATE()
CURRENT_TIMESTAMP
Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context:

mysql> SELECT NOW();
-> '1997-12-15 23:50:26'
mysql> SELECT NOW() + 0;
-> 19971215235026

Note that NOW() is only evaluated once per query, namely at the start of query execution. This means that multiple references to NOW() within a single query will always give the same time.

dreamcatcher

6:24 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A simple alternative is just to assign a date string, ie:

$date = date("D jS M, Y, g:i a");

then use a hidden input field:

<input type="hidden" name="name" value="<? echo $date;?>">

:)

raulwg

7:23 pm on May 9, 2003 (gmt 0)

10+ Year Member



Thanx dreamcatcher but if i use this i get only zero's in my message....I think i did everything right....I made an extra field called date with the property of datetime (default: 0000-00-00 00:00:00)

I also put the hidden input like u said:
<input type="hidden" name="date" value="<? echo $date;?>">

Is it important how to put the line below with the Y,M d,...etc?
$date = date("Y, M d, H:i s");
Don't know what I did wrong?

dreamcatcher

7:54 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just create a varchar field to hold the date info. No need for a timestamp in this situation.

:)

raulwg

8:24 pm on May 9, 2003 (gmt 0)

10+ Year Member



Gee....Thanx...just that simple and it worked.....

dreamcatcher

8:40 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool. I made the same mistake when I was learning.

Glad it worked ok.

:)