Current location: Hot Scripts Forums » Programming Languages » PHP » How to add the last login DATE in MySql database?


How to add the last login DATE in MySql database?

Reply
  #1 (permalink)  
Old 02-11-05, 08:16 AM
Edward Han Edward Han is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy How to add the last login DATE in MySql database?

Hi

Create username, password and lastlog for mysql database. Please advice how I can add the last login DATE everytime when the user login with the username and password?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-11-05, 11:58 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
when you check the user's auth info; if the user was authenticated, then do the INSERT INTO query..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-11-05, 09:51 PM
Edward Han Edward Han is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Hi NeverMind

I am still a newbie therefore kindly show me how to add using PHP?

Thanks!

Edward
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-12-05, 03:45 AM
Edward Han Edward Han is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Hi NeverMind

I tried inserting the date by doing the following but it did not insert the date into the same column as the username with password. Instead it simply adds into a new line without the username and password. How do I make it inserts into the existing user that login?

Please advice. Thanks!

PHP Code:

    require_once("connect.php");

    
$username $_POST['username'];
    
$password $_POST['password'];
    
$search_user_query "SELECT * FROM " TABLE_NAME " WHERE `" USER_NAME "`='$username' AND `" PASS_NAME "`='$password'";
    
$search_user_result = @mysql_query($search_user_query);
        
$query mysql_query("insert into TABLE_NAME set date=CURDATE()"); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-12-05, 04:34 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
use the UPDATE not INSERT INTO
PHP Code:

    $username $_POST['username'];

    
$password $_POST['password'];
    
$search_user_query "SELECT * FROM " TABLE_NAME " WHERE `" USER_NAME "`='$username' AND `" PASS_NAME "`='$password'";
    
$search_user_result = @mysql_query($search_user_query);
    
$query mysql_query("UPDATE "TABLE_NAME ."  SET date=CURDATE() WHERE "USER_NAME "='$username'"); 
if you enabled users to have the same username, then make the UPDATE query:
PHP Code:

$query mysql_query("UPDATE "TABLE_NAME ."  SET date=CURDATE() WHERE "USER_NAME "='$username' AND " PASS_NAME "='$password'"); 

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-12-05, 04:59 AM
Edward Han Edward Han is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Hi NeverMind

Thanks! It works great!

Edward
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 02-13-05, 11:43 AM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
I actually use the Datetime thing.

PHP Code:

$yourtable "CREATE TABLE IF NOT EXISTS " .SQL_PREFIX"yourtable (

  id int(11) NOT NULL auto_increment,
  datetime datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY (id)
)"

PHP Code:

$datetime date("Y-m-d H:i:s",time());

$query "INSERT INTO " .SQL_PREFIX"yourtable (datetime)
VALUES ('" 
.$datetime"')";
$result mysql_query($query) or die(mysql_error()); 
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 02:41 AM
inserting and retrieving date and time from mysql database stealth04 PHP 5 07-29-04 12:19 PM
Login script for MySQL db conundrum PHP 1 07-29-04 10:35 AM
cant add more than 1 mysql table with php script chrisb62 PHP 1 04-27-04 05:00 AM
Error while creating database (Errornumber 2002: "Can't connect to local MySQL server lylesback2 PHP 5 04-11-04 02:37 PM


All times are GMT -5. The time now is 12:35 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.