从HTML到PHP的数据始终为空

我正在使用php和html进行注册登录页面。但是我的php代码看不到php发送的数据。 下面是我的html和php文件。

<html>
<head>
    <meta charset="utf-8">
    <link href = '../css/login.css' rel = 'stylesheet'>
    <title> Login </title>
</head>
<body>
    <form action="../php/login.php" method="post">
    <input id = "loginButton" type="image" src ="../images/loginAndRegister.gif" alt="submit">
    <div class = "panel">

        <p> Login </p>
        <br>
        <br>
        <label> username </label>
        <br>
        <input type = "text" name = "username" required>
        <br>
        <label> password </label>
        <br>
        <input type = "password" name = "password" required>
        <br>
    </div>
    </form>
</body>
</html>

<html>
    <body>
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "dark_souls";

    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    $user = isset($_POST['username']) ? $_POST['username'] : NULL;
    $pass = isset($_POST['password']) ? $_POST['password'] : NULL;
    echo $user;

    $sql = "SELECT * FROM users WHERE username = '".$user."' AND password = '".$pass."'";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
      header("Location: ../templates/Home.html");
    } else {
      echo "Wrong Credentials";
    }
    ?>

    </body>
    </html>

我在php代码中写了“ echo $ user”只是为了检查它是否在工作。问题是我在工作时使用了完全相同的代码来注册ant。 请帮助!

评论
  • qnobis
    qnobis 回复

    可能是因为表单没有提交按钮。

    <input type="submit" value="Submit">