无法在数据库中插入一行

时间:2015-08-25 16:28:48

标签: php mysql mysqli

我想在数据库中插入记录,我不知道probolem在哪里 这是我的代码!

 <?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $status = "";
    $name = $_POST['name'];
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST[$password];

    $query = "INSERT INTO admins (name, email, username, password) ";

    $query .= "VALUES ('{$name}','{$email}','{$username}','{$password}')";

    $result = mysqli_query($connect , $query);

    if (isset($result)){
        $status = "Admin has been added";
    }else {
        $status = "Admin hasn't been added ";
    }
}
?>

<form action="add_user.php" method="post">
    <h3>Name</h3>
    <input name="name" placeholder="Name">
    <h3>Username</h3>
    <input name="username" placeholder="Username">
    <h3>E-mail</h3>
    <input name="email" placeholder="E-mail">
    <h3>Password</h3>
    <input name="password" placeholder="Password" id="password" type="password">
    <h3>Confirm Password</h3>
    <input name="confirm_pass" placeholder="Confirm Password" id="confirm_password" type="password" onkeydown="ValidatePass()">
    <p id="pass_state"></p>
    <div id="btn">
        <input type="submit" value="Create User dis" disabled>
    </div>
    <h4 style="color: orangered"><?php ?></h4>
</form>  

我知道那里有sqlInjections! 不要担心这只是为了当地的发展和学习目的:D

请帮忙!

1 个答案:

答案 0 :(得分:-1)

首先改变这一行

$password = $_POST[$password];

用这个

$password = $_POST['password'];

然后检查你的连接字符串,它对我来说没问题

相关问题