I’m trying to insert the current date/time to the database as the last time the user logged in. For some reason this doesn’t work.
Other insertion scripts running on the very same page work well, and the connection is ok.
I use the same syntax to insert other stuff throughout the whole site, so I don’t get what’s wrong.
I can guarantee that the else part is being executed when I’m entering my password.
Here’s the piece of code I am talking about.
if(!$pwVer){
// code to execute if the password is incorrect.
} else {
$dateT = date("Y-m-d H:i:s");
$up_date = $con->prepare("INSERT INTO tbl_user_test (user_last_login) VALUES (:l_login)");
$up_date->bindParam(':l_login', $dateT);
$up_date->execute();
validateUser($userid); //sets the session data for this user
header("Location: cart.php");
$con = null;
die();
}
Some background:
- $pwVer returns `true` if the password is correct.
- both `tbl_user_test` and `user_last_login` are written exactly as they’re in the database.
Thanks in advance!
There is no error visible in your code, so it should be executed. One possible problem could be that PDO is in silent mode, which doesn’t tell you what or if an error has occured. Set PDO to fail with an exception.
Also, there’s no need to construct the current date yourself; you can use SQL’s
NOW().