我是PHP和HTML的新手,自从我试图解决这个问题以来已经过去了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);
}
?>
答案 0 :(得分:0)
我是怎么做到的,
使用Wife
和Husband
创建一个单一表单,然后将input
名称加上前缀wi_
和hu_
,并且提交表单后,我将在服务器端处理它,并在验证/验证后,我将使查询插入带有相应输入的两行数据。
答案 1 :(得分:0)
不再担心!为php创建另一个第二个变量(即:firstname2,middlename2等)。然后做这个魔术
faSymLink
所以简称查询:INSERT INTO tablename ( columnnames )VALUES(*第一个php变量),(*第二个php变量)
Viola!