将登录信息插入mysql数据库

Uzz*_*Dey 1 php mysqli mysql-error-1064

我正在学习php mysql,但我遇到了这个问题.我无法将登录信息插入到我的数据库表中.我的数据库名称是loginapp,表名是用户.请查看我为其创建的代码----

<?php 
if(isset($_POST['submit'])){
   $username = $_POST['username'];
   $password = $_POST['password'];
    $connection = mysqli_connect('localhost', 'root', '','loginapp');
    if(!$connection){
    die("Database connection failed");
    }
    $query = "INSERT INTO users(username,password)";
    $query .= "VALUES ('$username', '$password')";
    $result = mysqli_query($connection, $query);
    if(!$result){
    die('query is faild' . mysqli_connect_error());
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login </title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

</head>
<body>

    <div class="container">
        <div class="col-xs-6">
             <form action="login.php" method="post">
                 <div class="form-group">
                    <label for="username">Username</label>
                     <input type="text"  name="username"class="form-control">
                 </div>
                  <div class="form-group">
                    <label for="password">Password</label>
                     <input type="password" name="password" class="form-control">
                 </div>
                 <input class="btn btn-primary" type="submit" name="submit" value="Submit">
             </form>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Sat*_*aty 5

在价值观之前需要空间

 $query = "INSERT INTO users(username,password)";

 $query .= " VALUES ('$username', '$password')";
            ^
Run Code Online (Sandbox Code Playgroud)

你的代码是开放的sql注入,检查下面的链接,以防止它

如何在PHP中阻止SQL注入?

要检查查询中的错误,请使用

printf("Errormessage: %s\n", $mysqli->error);
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/mysqli.error.php

检查与数据库使用连接时的错误

if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/mysqli.error.php

不要将普通密码存储到数据库使用中

http://php.net/manual/en/faq.passwords.php

http://php.net/manual/en/function.password-hash.php