Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:08:00+00:00 2026-05-24T07:08:00+00:00

I have a form in two sections on a webpage. Each section contains a

  • 0

I have a form in two sections on a webpage. Each section contains a variable number of rows (the user can add more rows). I have a PHP page which processes the form as an email, but I am now looking to extend this so that information is added to a My SQL database that I have in place. Below is the code for the form and the php processing page as it stands.

I have started to include the code for submitting the data to the MySQL table at the bottom of the PHP page, but I am not sure how to do this, given that there are a variable number of rows in two sections, and would be grateful for any help in getting this working.

Here is the HTML for the form:

<form method="post" name="booking" action="bookingengine.php">
    <fieldset>
        <h2>Waged/Organisation Rate</h2>
        <p>
            <input type="text" name="name[]">
            <input type="text" name="email[]">
            <input type="text" name="organisation[]">
            <input type="text" name="position[]">
        </p>
        <p><span class="add">Add person</span></p>
    </fieldset>

    <fieldset>
        <h2>Unwaged Rate</h2>
        <p>
            <input type="text" name="name2[]">
            <input type="text" name="email2[]">
        </p>
        <p><span class="add">Add person</span></p>
    </fieldset>

    <p><input type="submit" name="submit" id="submit" value="Submit and proceed to payment page" class="submit-button" /></p>

</form>

And here is the booking engine.php:

<? include 'connection.php'; ?>

<?php

$emailFrom = "****";
$emailTo = "****";
$subject = "Booking for Soteria Conference";

$body = "The following people have booked for the Soteria Conference in Derby:" . "\n\n" . "Waged/Organisation Rate:" . "\n\n";
$row_count = count($_POST['name']);
$row_count2 = count($_POST['name2']);



for($i = 0; $i < $row_count; $i++)
{
  // variable sanitation...
  $name = trim(stripslashes($_POST['name'][$i]));
  $email = trim(stripslashes($_POST['email'][$i]));
  $organisation = trim(stripslashes($_POST['organisation'][$i]));
  $position = trim(stripslashes($_POST['position'][$i]));

  // this assumes name, email, and telephone are required & present in each element
  // otherwise you will have spurious line breaks. 
  $body .= "Name: " . $name . "    Email: " . $email . "  Organisation: " . $organisation . "   Position: " . $position . "\n\n";
}

$body .= "Unwaged Rate:" . "\n\n";

for($j = 0; $j < $row_count2; $j++)
{
  // variable sanitation...
  $name2 = trim(stripslashes($_POST['name2'][$j]));
  $email2 = trim(stripslashes($_POST['email2'][$j]));

  // this assumes name, email, and telephone are required & present in each element
  // otherwise you will have spurious line breaks. 
  $body .= "Name: " . $name2 . "    Email: " . $email2 . "\n\n";
}

// send email 
$success = mail($emailTo, $subject, $body, "From: <$emailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=payment.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}

?>

Here is the structure of connection.php:

<?php

$hostname = "localhost";
$database = "****";
$username = "****";
$password = "****";

$conn = mysql_connect($hostname, $username, $password) or die ('Error connecting to mysql');
mysql_select_db($database);

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:08:01+00:00Added an answer on May 24, 2026 at 7:08 am

    I’m not sure what you mean. But your HTML code should be more like this :

    <p>
      <input type="text" name="persons[][name]">
      <input type="text" name="persons[][email]">
      <input type="text" name="persons[][organisation]">
      <input type="text" name="persons[][position]">
    </p>
    

    And then at the end of your PHP script

    $values = array();
    foreach ($_POST['persons'] as $person) {
        // Sanitize your datas
        ...
        // SQL VALUES TO INSERT
        $values[] = '(' . $person['name'] . ',' . $person['email'] . ',' . $person['organisation'] . ',' . $person['position'] . ')';
    }
    $query = "INSERT INTO person (name, email, organization, position) VALUES " . implode(',', $values);
    

    The same logic applies for Unwaged rates

    edit if you want to keep your HTML

     $values = array();
    
     for($i = 0; $i < $row_count; $i++) {
         // variable sanitation...
         $name = trim(stripslashes($_POST['name'][$i]));
         $email = trim(stripslashes($_POST['email'][$i]));
         $organisation = trim(stripslashes($_POST['organisation'][$i]));
         $position = trim(stripslashes($_POST['position'][$i]));
    
         // this assumes name, email, and telephone are required & present in each element
         // otherwise you will have spurious line breaks. 
         $body .= "Name: " . $name . "    Email: " . $email . "  Organisation: " . $organisation . "   Position: " . $position . "\n\n";
    
         //prepare the values for MySQL
         $values[] = '(' . $name . ',' . $email . ',' . $organisation . ',' . $position . ')';
    }
    $query = "INSERT INTO person (name, email, organization, position) VALUES " . implode(',', $values);
    
     And for unwaged rate
    
     $values = array();
    
     for($i = 0; $i < $row_count; $i++) {
         // variable sanitation...
         $name = trim(stripslashes($_POST['name'][$i]));
         $email = trim(stripslashes($_POST['email'][$i]));
    
         // this assumes name, email, and telephone are required & present in each element
         // otherwise you will have spurious line breaks. 
         $body .= "Name: " . $name . "    Email: " . $email . "\n\n";
    
         //prepare the values for MySQL
         $values[] = '(' . $name . ',' . $email . ')';
    }
    $query = "INSERT INTO person (name, email) VALUES " . implode(',', $values);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have divided form in to two sections: sec1 and sec2 . Each section
I have two sections on my PHP form. One section allows to enter Customer
I have an input form with two textareas allowing a user to type in
I have two sections in a form, and I have a button that toggles
So I have a fairly large form with two different sections. Both sections start
I have a grouped UITableViewController with one section and many rows. Each cell consists
I am working on a form with a two different sections. Both sections have
I have a form where a user can upload a file to the sites
I have two sections(primary and secondary) in a form with several textboxes which display
I have two dropdowns @using (Html.BeginForm()) { <fieldset> <legend></legend> <label>User details</label> <section> @Html.LabelFor(model =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.