...

View Full Version : building a form with multiple entries



jamesd116
05-29-2011, 05:09 AM
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

mlseim
05-29-2011, 05:22 AM
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]


.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum