Page 1 of 1

phpformgen question - multiple posts at once

Posted: Sat Apr 15, 2006 2:04 am
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!

Posted: Sat Apr 15, 2006 9:09 am
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',
      ),
    ),
  )

Posted: Sat Apr 15, 2006 3:23 pm
by ecuguru1
Thanks! I'll go get lost and come back, but that's a great approach.