Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    building a form with multiple entries

    I am not sure if this is possible but here is what I am trying to do. I am very new to PHP and tried to look through some of the php codes and i am not sure i foreach or while will work for this or not. I do not have any coding because I am not sure where to start with this.

    db includes
    location id
    state name
    county name
    city name


    In stead of adding each city in indivudally as

    state
    county
    city

    I want to enter multiple entries at once with the state and county being added to each entry city and each city going into the db table as its own entry

    form to be constructed as

    state
    county

    city
    city
    city
    city
    city
    city
    city
    city
    city
    city
    city
    city
    city
    city
    any suggestions creating the form is not the problem but creating the separate entries while inserting the state and county into each one.
    Thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Your form will have multiple input boxes ...
    they will all have the same name with square brackets.

    State: <input type="text" name="state[]">
    County: <input type="text" name="county[]">
    City: <input type="text" name="city[]">

    Repeat those as many times as you want in your form.

    The square brackets create an "array" that will be used in the PHP script to read them all.

    <?php
    $city=$_POST['city'];

    In doing that, $city is now an array (not a single variable).

    You will process $city as an array, by looping through them all.
    Same with $state and $county. Each one starts with array element 0.
    The first city is, $city[0]


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •