我希望用户输入的数据被提交到数据库。但由于某种原因,我的代码不工作?HTML表单不会提交到数据库
<form action="newpostsubmit.php" method="post">
<h2 class="form-signin-heading">New Post (beta)</h2>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title" id="title">
</div>
<br>
<div class="form-group">
<label for="post">Post</label>
<textarea class="form-control" rows="5" name="post" id="post"></textarea>
</div>
<br>
<input type="submit">
</form>
PHP提交
<?php
//Connecting to sql db.
$connect = mysqli_connect("localhost","root","pwd","db");
//Sending form data to sql db.
mysqli_query($connect,"INSERT INTO posts (title, post)
VALUES ('$_POST[title]', '$_POST[post]')";
?>
的名称与HTML输入必须在POST的名称,例如$ _ POST [标题] – Mihai
符合我刚才改变,但仍然没有工作 – mattmill98
是您的文件名为newpostsubmit.php?是不是在同一个文件夹中与HTML文件? – Mihai