In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Tom Malone) wrote:

> I am using sessions to track visitors to my site, and one of the things I'd
> like to do is add a time-stamp to each entry in my MySQL database. The
> problem is that, for some reason, the time-stamp part only seems to work
> part of the time.  I know it can't be, but it almost seems arbitrary - i
> haven't been able to determine a pattern. 

Just a guess, but "arbitrary" sounds as though the timestamp format you're 
inserting may not be the right one for the datatype of the field it's being 
inserted into.  And the format you're using is not recognizable to me as a 
standard format for a date, datetime, or timestamp field.

> $now = date("D M j, H:i");
> $sql = "INSERT INTO $table_name
>    (ndx, id, time, ip_address, browser, origin)
>    VALUES
>    (\"\", \"$id\", \"$now\", \"$ip_address\", \"$browser\", \"$origin\")";
> $result = mysql_query($sql, $connection) or die("Couldn't update session
> logs. MySQL error: " . mysql_error());

But rather than creating/adjusting the timestamp in PHP, why not use the 
MySQL built in function now() (for a date or datetime field) or NULL (for a 
timestamp field)?

"INSERT INTO $table_name  (ndx, id, time, ip_address, browser, origin)   
VALUES  (\"\", \"$id\", now(), \"$ip_address\", \"$browser\", \"$origin\")";

or 

"INSERT INTO $table_name  (ndx, id, time, ip_address, browser, origin)   
VALUES  (\"\", \"$id\", NULL, \"$ip_address\", \"$browser\", \"$origin\")";

(BTW, "time" is a reserved word in MySQL since it is the name of a field 
type.  I'm surprised MySQL isn't reporting a warning about that.  Still, 
you should change that field's name to something else.)

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to