I am currently working on a project where I need to store information in a database for member login page. Currently, I am working on storing the time the user enters their credentials. It keeps popping up with "Duplicate entry '0000-00-00 00:00:00' for key 'PRIMARY'", which I understand everything except for why my time will not process as an actual time... Below the section of my code that I am working with... maybe something is wrong? Or is there a better way to call the current timestamp than what I am doing.
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE)
or die("Failed to connect");
if(isset($_POST['submit'])) {
date_default_timezone_set('America/Phoenix');
$username = mysql_real_escape_string($_POST['userlogin']);
$password = mysql_real_escape_string($_POST['userpassword']);
$today = date("F j, Y, h:i:s A");
$sql = "SELECT * FROM Member WHERE loginName = '".$username."' AND password = '".$password."'"; //checks for user in database
//--password = SHA2(CONCAT('bar','paz'),512)";
$result = $mysqli->query($sql) or die($mysqli->error); //shoots an error if something is wrong
if($result->num_rows < 1) // if the username/password is incorrect then an error message appears
{
echo "Invalid username/password combination. Please try again.";
}
else
{
echo "Welcome."; //Successful
$today = date("F j, Y, h:i:s A");
header('Location: thankspage.html');
$sql = " INSERT INTO Login (loginName,loginTime)
VALUES ('$username', '$today' ) "; // creates the login time.
$result = $mysqli->query($sql) or die ($mysqli->error); // shoots an error if i did something wrong.
}
}