tags:

views:

197

answers:

2

Here is the table of interest when exported via phpMyAdmin:

CREATE TABLE IF NOT EXISTS `users` (
  `ip` varchar(20) NOT NULL,
  `lastcheck` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Here is the query:

mysql_query("REPLACE INTO users SET ip = '$uip', lastcheck = '$tim'") or throwerror("part2 ".mysql_error());

$tim is set to be time();

Now for some reason lastcheck is still set as 0000-00-00 00:00:00.

Can anyone help? Thanks.

+2  A: 

try using date('Y-m-d H:i:s') in stead of time()

time() in php returns a unix timestamp and that isn't a valid insert for MyySQL datetime

hope this helps

Kennethvr
+4  A: 

I am not sure if maybe I understand your problem, looking at column lastcheck declaration CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP that means when ever you update (ip = '$uip') this column an automatic date update will also happen lastcheck. Which mean you can write you update statment as follows :

REPLACE INTO users SET ip = '$uip';

That should also update the lastcheck field, and I think it's better to use the mysql date functions to store your date/time than writing them in php and saving them as string in the database...

Ronald Conco
Ah, wonderful. I was thinking how on earth could I prevent PHP and MySQL times having a mismatch or something...
a2h
I would recommend you look at http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html, it's important to have the mysql date the same as the php, this can be set as you make a connection to mysql server....
Ronald Conco