我目前正在从事一个项目,我需要将信息存储在数据库中以供会员登录页面使用。目前,我正在存储用户输入凭据的时间。它不断弹出“重复条目'0000-00-00 00:00:00' for key 'PRIMARY'”,除了为什么我的时间不会作为实际时间处理之外,我理解所有内容......在下面的部分我正在使用的代码......也许有问题?或者有没有比我正在做的更好的方法来调用当前时间戳。
$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.
}
}