当我使用post方法插入数据时,数据未显示在数据库中

时间:2019-05-17 01:47:35

标签: php mysql forms post

我必须制作一个基本形式,该形式使用称为login的表将“登录数据”插入数据库。与数据库的连接成功,可以键入并提交数据,但是当我检查数据库时,该表仍然为空。 我对数据库中的其他表单及其各自的表使用了完全相同的方法,并且工作正常。我知道可能有更有效的方法来做到这一点,但这是我在课堂上学到的。谢谢:)

据我了解,这是一个非常简单的过程。表单中的每个输入都有一个name属性,然后我将其分配给变量。然后,我仅使用查询将这些变量插入数据库。同样,这对于“联系我们”表单有两个输入项,并且其表中只有另外两列,效果很好。

<?php
$server = "localhost";
$username = "root";
$password = "";
$dbname = "dealer";

// Create connection
$conn = new mysqli($server, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

//insert data
if($_POST){
    $user = $_POST["txtUser"];
    $password = $_POST["txtPassword"];

    mysqli_query($conn, "insert into inicio_sesion (usuario, contraseña) 
                         values('$user', '$password')");

    header('Location: form2.php');
}
?>

<html>
    <head>
        <title>Contact Us</title>
    </head>
    <body>

        <h1>Login</h1>

        <form method="post">
            <label>usuario: </label>
            <input type="text" name = "txtUser">
            <br>
            <label>contraseña: </label>
            <input type="text" name = "txtPassword">
            <br>
            <input type="submit" name="btnSend" value="Send">
        </form>
    </body>
</html>

我没有收到任何错误消息,我只是不知道数据在哪里或为什么它不显示在数据库中。

0 个答案:

没有答案
相关问题