我试图在用户登录时显示用户的上次登录日期和时间。我的数据库中有一个时间戳。我能够在每次用户登录时存储登录时间但是对PHP不熟悉,我无法显示相同的内容。请帮助我使用MySQL和PHP显示存储在数据库中的时间戳类型变量。
我发布了index.php的代码,我想显示上次登录时间和日期。
session.php的代码
<?php
// Establishing Connection with Server by passing server_name, user_id and
password as a parameter
$connection = mysql_connect("localhost", "root", "");
// Selecting Database
$db = mysql_select_db("exp", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from user where
username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
?>
index.php的代码:
<?php
include('session.php');
?>
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello
<i><?php echo $login_session;
$result = mysql_query("SELECT UNIX_TIMESTAMP(lastlog) FROM user WHERE
username= '" .mysql_real_escape_string($_SESSION['login_user']). "' ");
if($result)
{
$data = mysql_fetch_assoc($result);
echo $data['lastlog'];
}
mysql_query("UPDATE user SET lastlog = now() WHERE
username= '" .mysql_real_escape_string($_SESSION['login_user']). "'");
?></i>
</h1>
</body>
</html>`
我的数据库中的时间戳列是最后的日志。另外,帮助我存储和显示创建日期。请帮我解决这个问题...... 感谢提前!!!