我已经对主网页进行了简单的登录。如果用户登录成功,则应将用户名,昵称和日期插入数据库" userdata"为什么不是这样的?我没有收到任何错误,但我的数据库没有更新并保持空白。
PHP:
<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if($_POST['submit']) {
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$sql = "SELECT id, username, password, nickname FROM users WHERE username = '$username' AND activated = '1' LIMIT 1";
$connect = mysqli_connect("", "", "", "root_root");
$query = mysqli_query($connect, $sql);
if ($query) {
$row = mysqli_fetch_row($query);
$userId = $row[0];
$dbUsername = $row[1];
$dbPassword = $row[2];
$userLabel = $row[3];
}
if ($username == $dbUsername && $password == $dbPassword) {
$_SESSION['username'] = $username;
$_SESSION['id'] = $userId;
$_SESSION['nickname'] = $userLabel;
$date = date('m/d/y | H:i:s');
if ($dbPassword == "password") {
header('Location: firstlogin.php');
}
else
mysqli_query($connect, "INSERT INTO userdata (username, name, timein) VALUES ('$username', '$userLabel', '$date')");
header('Location: main.php');
}
else {
$error = "Error: Invalid username or password.";
}
}
?>