我希望用戶輸入的數據被提交到數據庫。但由於某種原因,我的代碼不工作?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