嗨我正在创建一个登录页面,它将数据插入到php表中,但它似乎没有将数据插入表中我在1个数据库中有2个表 hrms
<?php
$servername = "localhost";
$user = "root";
$dbpassword="";
$dbname = "hrms";
$username=$_POST['username'];
$passphrase=$_POST['passphrase'];
$conn = new mysqli($servername, $user, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM user WHERE username='$username' AND passphrase='$passphrase'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$sql = "INSERT INTO access (user, status)
VALUES ('John', 'locked')";
header("location: main.php");
} else {
header("location: index.php");
}
$conn->close();
?>
答案 0 :(得分:2)
您忘记执行查询,请执行以下操作:
$sql = "INSERT INTO access (user, status) VALUES ('John', 'locked')";
$conn->query($sql);