我正在學習php mysql,但我正面臨着這個問題。我無法將登錄信息插入到我的數據庫表中。我的數據庫名稱是loginapp,表名是用戶。請仔細閱讀這些我創建了----插入登錄信息到mysql數據庫
<?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>
感謝您的努力。 –