Reputation: 57
$qry = "SELECT user, TIME_FORMAT(last_login_time, '%H:%i') FROM login_attempts WHERE user = '".$username."'";
$result = mysql_query($qry,$this->connection);
if(!$result || mysql_num_rows($result) <= 0){
mysql_query ("INSERT INTO login_attempts(userid, user, attempts, last_login_time) VALUES('', '$username', '{$_SESSION['count']}', '{$_SESSION['login_time']}')");
}
else{
$row = mysql_fetch_assoc($result);
$_SESSION['login_time'] = $row["last_login_time"];
mysql_query ("UPDATE login_attempts SET attempts = '" .$_SESSION['count']."' WHERE user = '".$username."'");
}
In the above code I'm storing my $_SESSION['login_time']
value in 'login_attempts
' table where the column name is 'last_login_time'.
Now I need to fetch this value and store it back in $_SESSION['login_time']
array so that I get to know when the last time user tried to enter. How shall I fetch this value???
The datatype of 'last_login_time'
column is 'timestamp'.
Upvotes: 0
Views: 154
Reputation: 34063
You need to alias your TIME_FORMAT
column in order to reference it.
SELECT user, TIME_FORMAT(last_login_time, '%H:%i') AS last_login_time ...
Also, why not UPDATE
the login attempts to SET attempts = attempts + 1
?
Upvotes: 1