无法更新表格中的数据

时间:2016-02-25 13:02:42

标签: php mysql

嗨我正在创建一个登录页面,它将数据插入到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();
?>

1 个答案:

答案 0 :(得分:2)

忘记执行查询,请执行以下操作:

$sql = "INSERT INTO access (user, status) VALUES ('John', 'locked')";
$conn->query($sql);