嗨,我尝试将他们输入的用户名插入到 logattempt 表中 但它无法识别我已经声明的 $username
<?php
$servername = "localhost";
$user = "root";
$dbpassword="";
$dbname = "hrms";
$username=$_POST['username'];
$password=$_POST['password'];
$conn = new mysqli($servername, $user, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header("location: main.php");
} else {
$sql = "INSERT INTO logattempt (id, username, timest, failedatt)
VALUES ('John', '$username', 'john@example.com','asdfasdf')";
$conn->query($sql);
header("location: index.php");
}
$conn->close();
?>
最佳答案
假设你将Id字段设置为自动递增
更改自
$sql = "INSERT INTO logattempt (id, username, timest, failedatt)
VALUES ('John', '$username', 'john@example.com','asdfasdf')";
至
$sql = "INSERT INTO logattempt (id, username, timest, failedatt)
VALUES (null, '$username', 'john@example.com','asdfasdf')";
关于php - 无法将输入的 $username 插入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35645847/