Display last login time in php

I am new to Php. I created a registration and registration system that works fine, but I want to display the last login time when a user logs in. I have a table (TIMESTAMP) that stores data as 2013-03-08 00:00:00. It displays the date, but not the time. I also want to display these results when a user logs in.

I use the code below when the data validation is successful and the user session variable is set.

$currentDate = date('Ymd g:i:s'); mysql_query('UPDATE `users` SET `last_sctivity` = "' . $currentDate . '"'); 
+4
source share
4 answers

you can also use now() in the query if you are not using $currentDate anywhere in the code

 mysql_query('UPDATE `users` SET `last_sctivity` = now()'); 

also make sure the last_sctivity column is timestamp , not date

+2
source

Try:

$currentDate = date('Ymd h:i:s');

Edit g:i:sh:i:s

+1
source

Do not insert dates, etc., using PHP functions in MySQL when MySQL has the corresponding functions for this. Use MySQL NOW() instead.

Mixing PHP and MySQL is not recommended if necessary.

0
source
 $today = date('Ymd, g:i a'); $last = ("UPDATE users SET lastaccess = '$today'"); $query = mysqli_query($con, $last); 
0
source

All Articles