I have a database that I would like to keep track of who and when people are logging on. I created a table called users. It has three fields, id, user, date. I created this script that is executed when they log in.
<?php

$db = mysql_connect("","","");

mysql_select_db("",$db);

$today= getdate();

$query = "INSERT INTO users VALUES ('','$user','$today')";
mysql_query($query);


?>

The script enters the user ok, but enters a zero value for the date and time.

If I add print_r($today); to the script, it returns the correct date and time to the browser, but not the database.

Thanks in advance for any help!

Stick

$today becomes an array, so it itself has no value

What I suggest is to turn $today from an array to a string by doing this:

$today = serialize($today); // turns into a string

Then insert $today into the database like you normally would. In order to get the data back from $today, just unserialize before using, like so:

$user = mysql_fetch_array(mysql_query("SELECT * FROM users");

$today = unserialize($user['today']);

// $today is now useable again!

Gary,
I updated my script as follows.

db = mysql_connect("","","");

mysql_select_db("",$db);

$today= getdate();

$today = serialize($today);

$query = "INSERT INTO users VALUES ('','$user','$today')";
mysql_query($query);

It still gives me a zero value in the table.
I have the field type set to timestamp. Is this correct?

Thanks for your help!

Stick

Field type should be something like TEXT.

If you want timestamp, then you need a UNIX timestamp. So do something like

$query = "INSERT INTO users VALUES ('','$user',time())";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.