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 6644597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:11:08+00:00 2026-05-26T00:11:08+00:00

I have a PHP form which shows one ‘User details’ block by default. ‘User

  • 0

I have a PHP form which shows one ‘User details’ block by default. ‘User details’ section has first name, last name and address etc. I have a requirement to repeat the same block after clicking on the button so the user can enter ‘n’ number of users into on the form. Also I need to save all the information in MySQL database. What is the best way to achieve this? Please let me know. I appreciate any help.

Thank you.

  • 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-26T00:11:09+00:00Added an answer on May 26, 2026 at 12:11 am

    I would use jQuery to add additional form elements. You’ll need to give each element a different ‘name’ attribute though- I’d use something like name=’user1name’ (and in the next username field name=’user2name’). Comment on my post if you need specific help with that. When the form submits, I’d use php to loop through each set of fields with an insert statement at the end of the loop.

    PHP is something like this:

    for ($i = 1; is_null($_POST['name' . $i]) == false; $i++) {
        $name = $_POST['user' . $i . 'name'];
        // repeat for all your fields
    
        // do your insert statement here - 1 insert per user created
        mysql_query("INSERT INTO table_name (Name, Address, ...) VALUES ('$name', '$address', ...)");
    }
    

    jQuery is something like this:

    Existing HTML
    Should only have 1 div with class=user at this point

    <div id='fields'>
        <div class='user'>
            <input type='text' name='user1name' />
            <input type='text' name='user2name' />
            ... more elements ...
        </div>
    </div>
    

    jQuery

    var userFields = $("div.user").clone();
    $(userFields).appendTo("div#fields");
    $("div#fields").children("div.user:last").children().each(function() {
        // change names here!
    });
    

    This will copy the existing field and add its copy to the fields div. It will also set the new names for the second set of user fields. Note: you only need ot set userFields once, and then you can use $(userFields).appendTo("div#fields"); as many times as you need to (as long as the userFields variable is in scope).

    If you have event handlers attached to your elements in the user field, use $("div.user").clone(true, true); instead of $("div.user").clone();.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this page which loads quotes. It has a search form wherein if
I'm currently building a web-app that has one section where the user sees a
I have a form for a user to change their settings. It has 5
I have buy.php with a form where you enter items, quantity, shipping data, etc.
I have an HTML form - with PHP, I am sending the data of
I have code with the following form: <?php function doSomething{ //Do stuff with MySQL
The basics: I have a contact form that uses php to validate the forms.
I have a rewrite rule of the following form: RewriteRule ^foo/([a-zA-Z0-9]+)$ foo.php?arg=$1 [qsa,nc] It
I have a form which is validated through jquery, but I need the blur
I have a form field in Drupal which I need some help with. The

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.