2015-12-23 65 views
2

我對PHP和HTML相當陌生,自從我一直試圖解決這個問題以來,已經有2天了。通過使用一個提交按鈕將數據從2個表單傳遞到數據庫

我想從這些表單傳入數據到我的數據庫的表中,但我無法做到這一點,因爲這兩個表單只使用相同的標籤。 The 2 Forms
The table to which I'm trying to send the data

<?php 
    if(isset($_POST['submitted'])) 
    { 
     include('config/config1.php'); 
     global $conn; /* para makuha ang variable galing sa config/config1. */ 

     $firstname1 = $_POST["firstname"]; 
     $middlename1 = $_POST["middlename"]; 
     $lastname1 = $_POST['lastname']; 
     $sex1 = $_POST['sex']; 
     $household_head1 = $_POST['household_head']; 
     $household1 = $_POST['household']; 
     $civil_status1 = $_POST['civil_status']; 
     $bday1 = $_POST['birthdate']; 
     $bplace1 = $_POST['birthplace']; 
     $citizenship1 = $_POST['citizenship']; 
     $occupation1 = $_POST['occupation']; 
     $sponsors_female1 = $_POST['sponsors_female']; 
     $sponsors_male1 = $_POST['sponsors_male']; 
     $email1 = $_POST['email']; 
     $date_of_seminar1 = $_POST['date_of_seminar']; 
     /****  Query  ****/ 
     $insrtBptm = "INSERT INTO parishioner (firstname,middlename,lastname,sex,household_head,household,civil_status,birthdate,birthplace,citizenship,occupation,sponsors_female,sponsors_male,email,date_of_seminar) 
         VALUES ('$firstname1','$middlename1','$lastname1','$sex1','$household_head1','$household1','$civil_status1','$bday1','$bplace1','$citizenship1','$occupation1','$sponsors_female1','$sponsors_male1','$email1','$date_of_seminar1')"; 
     $update = "UPDATE parishioner SET Parishioner_idParishioner = idParishioner 
        WHERE Parishioner_idParishioner IS NULL AND idParishioner IS NOT NULL"; 
     header("Location:Home.php"); 
     /****  Validation ****/ 
     if(!mysqli_query($conn,$insrtBptm)) 
     { 
      die("Error not queried". mysqli_error()); 
     } 
     if(!mysqli_query($conn,$update)) 
     { 
      die("Update error !". mysqli_connect_error()); 
     } 
     mysqli_close($conn); 
    } 
?> 
+1

您可以使用所有字段的單個表單@ Jake152 – Gayathri

+0

從您的屏幕快照中,提交按鈕僅發佈丈夫表單的數據。 – Gayathri

+0

而不是使用兩個表單的,你應該使用單一形式 併爲丈夫和妻子相同的字段,你可以使用數組 名=「妻子[FIRST_NAME]」和丈夫的名字=「丈夫[FIRST_NAME]」 提交你會得到兩個陣列的妻子和丈夫 – softsdev

回答

0

我怎麼會做它, 創建兩個WifeHusband,然後他們的前綴名稱inputwi_hu_分別一個單一的形式,一旦形式提交然後我會在服務器端進行處理,驗證/驗證後,我會查詢插入兩行數據與各自的輸入。

0

不用擔心!爲php創建另一個第二個變量(即:firstname2,middlename2等)。然後做這個魔法

$insrtMar = "INSERT INTO parishioner (firstname,middlename,lastname,sex,household_head,household,civil_status,birthdate,birthplace,citizenship,occupation,sponsors_female,sponsors_male,email,date_of_seminar) VALUES ('$firstname1','$middlename1','$lastname1','$sex1','$household_head1','$household1','$civil_status1','$bday1','$bplace1','$citizenship1','$occupation1','$sponsors_female1','$sponsors_male1','$email1','$date_of_seminar1'),('$firstname2','$middlename2','$lastname2','$sex2','$household_head2','$household2','$civil_status2','$bday2','$bplace2','$citizenship2','$occupation2','$sponsors_female2','$sponsors_male2','$email2','$date_of_seminar2')"; 

所以對於短查詢:INSERT INTO 表名COLUMNNAMES)VALUES(* 1 PHP變量),(*第二PHP變量)

中提琴!

相關問題