| | |
Recording time stamp
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2005
Posts: 20
Reputation:
Solved Threads: 0
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
<?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:
[php]$today = serialize($today); // turns into a string[/php]
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:
[php]$user = mysql_fetch_array(mysql_query("SELECT * FROM users");
$today = unserialize($user['today']);
// $today is now useable again!
[/php]
What I suggest is to turn $today from an array to a string by doing this:
[php]$today = serialize($today); // turns into a string[/php]
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:
[php]$user = mysql_fetch_array(mysql_query("SELECT * FROM users");
$today = unserialize($user['today']);
// $today is now useable again!
[/php]
•
•
Join Date: Feb 2005
Posts: 20
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- I just need TIME not Date. (MS SQL)
- date and time in file name (VB.NET)
- Convert time stamp to date using php (PHP)
- File with date + time (Python)
- Perl- How to call an event after a time delay (Perl)
- Need real time in XP (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: serch mysql for many fields
- Next Thread: Writing vBulletin Hacks
| Thread Tools | Search this Thread |
apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip javascript joomla limit link login mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop remote script search server sessions sms smtp soap source space sql strip_tags subversion support! survey syntax system table template tutorial undefined update upload url validator variable video virus web window.onbeforeunload=closeme; youtube





