2017-03-07 70 views
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')"); 
+0

你的提交按鈕必須在表格裏面,只要你沒有用javascript處理提交內容 – hassan

+0

1. s ubmit按鈕必須位於表單內(如果頁面刷新用於提交表單)。 '$ connect'代碼缺失 –

回答

0

你有一個表格裏面的表格是錯誤的。像這樣做:

<form method="POST" action="addtodatabase.php" > 
     <!-- Your inputs --> 
</form> 

而且,把你的提交表單內按鈕:

<form method="POST" action="addtodatabase.php" > 
     <!-- Your inputs --> 
     <input type="submit" value="Submit" /> 
</form> 

或者,如果提交按鈕外,按鈕的form屬性設置爲formid

<form id="myForm" method="POST" action="addtodatabase.php" > 
     <!-- Your inputs --> 
</form> 

<input type="submit" value="Submit" form="myForm" /> 
+0

非常感謝你的幫助 –