Jump to content

Recommended Posts

I have a form that will submit x number of people.

textboxes:

name=fname[]

name=lname[]

name=position[]

 

The x could be 1 person, 2 or 7 people, etc....

I'll have that number sent in the form also via a textbox name=num

 

For each person I'll need to add their fname, lname and position to a database.

 

How can I process this form as an array?

 

I could do the:

foreach($_POST['fname'] AS $fname)
   echo $fname;

 

but then I'd have to do that loop for each item....fname, lname and position....is there a more effiecient way?

 

thanks

 

 

Yes using one loop not 3. You must make sure that all arrays are of the same size

for($x = 0; $x < count($_POST['fname']); $x++) {
  mysql_query("INSERT INTO table SET fname='".mysql_real_escape_string($_POST['fname'][$x])."', lname='".mysql_real_escape_string($_POST['lname'][$x])."', position='".mysql_real_escape_string($_POST['position'][$x])."'");
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.