phpformgen question - multiple posts at once

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ecuguru1
Forum Newbie
Posts: 3
Joined: Sat Apr 15, 2006 12:20 am

phpformgen question - multiple posts at once

Post by ecuguru1 »

I've got a form (Created by phpformgen) that feeds an sql database.
I'd like to setup my php form so that I can add multiple records at one time (replicate the same form x times on one html page) and have the php script that receives the data cycle through the records making posts for each entry.

Is there an easy way to do this in php? How can I take a php script that's accepting data from one sql form, and have it cycle through a series of records posted at the same time?
Do I need to make unique form names, or can I do something like:
&name=name&pass=pass&name=name1&pass=pass1

I'm a perl convert, and in Perl we can treat the field names as arrays, essentially making it foreach (@name).

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Naming each in such a way that PHP generates an array from it works best in my experience.

Code: Select all

<input type="text" name="sql[0][name]" />
<input type="text" name="sql[0][foo]" />
<input type="text" name="sql[0][bar]" />
<input type="text" name="sql[1][name]" />
<input type="text" name="sql[1][foo]" />
<input type="text" name="sql[1][bar]" />
<input type="text" name="sql[2][name]" />
<input type="text" name="sql[2][foo]" />
<input type="text" name="sql[2][bar]" />
doing a var_export() or $_POST would show something like

Code: Select all

array(
  'sql' => array(
    0 => array(
      'name' => 'Joe',
      'foo' => 'asiago',
      'bar' => 'oranges',
      ),
    1 => array(
      'name' => 'Jane',
      'foo' => 'gouda',
      'bar' => 'apples',
      ),
    2 => array(
      'name' => 'Jeff',
      'foo' => 'monterey jack',
      'bar' => 'kiwi',
      ),
    ),
  )
ecuguru1
Forum Newbie
Posts: 3
Joined: Sat Apr 15, 2006 12:20 am

Post by ecuguru1 »

Thanks! I'll go get lost and come back, but that's a great approach.
Post Reply