I'm attempting to create a log when a user logs in through a MySql table and PHP, but nothing is showing up in my table. Everything else in my code works fine. Specifically I am attempting to store the Date, Time, IP of the accessor, Machine name of the accessor, and the username
I'm using
$username = $member['username'];
$ip = $_SERVER[REMOTE_ADDR];
$date = date('Y-m-d H:i:s');
$host = gethostbyaddr($ip);
$query = "INSERT INTO IP_LOG (DateTime, MachineName, IPAddress, Username) VALUES ($date,$host,$ip,$username)";
$result=mysql_query($qry);
to get the info, create the query and log the info.
The code for the whole process really relies here when it checks if the login was successful
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
$username = $member['username'];
$ip = $_SERVER[REMOTE_ADDR];
$date = date('Y-m-d H:i:s');
$host = gethostbyaddr($ip);
$query = "INSERT INTO IP_LOG (DateTime, MachineName, IPAddress, Username) VALUES ($date,$host,$ip,$username)";
$result=mysql_query($qry);
session_write_close();
header("location: home.php");
//TODO: Log all Information
exit();
}else {
//Login failed
$errmsg_arr[] = 'user name and password not found';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
}
I know it can successfully validate the credentials, but I can't seem to get the logging to work.