2
,這是我的表單.html文件得到連接到adddatabase.php頁.having名字和secondname無法從網頁數據添加到數據庫
<form action="addtodatabase.php" method="post">
<div class="container">
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="firstname" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="secondname" placeholder="Text input"><br/>
</div>
</form>
<button type="submit" class="btn btn-default">Submit</button>
</form>
addtodatabase.php頁面如下。
if (isset($_POST)) {
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$secondname = isset($_POST['secondname']) ? $_POST['secondname'] : '';
echo 'Your first name is ' .$firstname. '<br>';
echo 'Your second name is ' .$secondname. '<br>';
}
mysqli_query($connect,"INSERT INTO form_details(firstname,secondname)
VALUES('$firstname','$secondname')");
你的提交按鈕必須在表格裏面,只要你沒有用javascript處理提交內容 – hassan
1. s ubmit按鈕必須位於表單內(如果頁面刷新用於提交表單)。 '$ connect'代碼缺失 –