Jump to content

[SOLVED] Insert into database question (multiple rows)


forumnz

Recommended Posts

I have a form with with 2 text fields.

The user is able to add more fields using javascript.

 

Basically, I am wondering how I would insert multiple rows into a database. Normally I would know how to do this, but the amount of rows is uncertain (could be 1 or 100).

 

I suppose I would use an array? How would I do that?

 

More info: the form would submit text fields named:

name1 email1

name2 email2

name3 email3

etc...

 

Thanks, Sam :)

Oh one more thing!

 

The user is able to delete sets of test fields (name and email), but each time a new one is created, a new number is generated. So basically the form might submit something like:

 

name1 email1

name3 email3

name18 email18

 

Meaning all the numbers inbetween contain no data so they shouldn't be inserted - how would I get around this?

 

Thanks!

:D

Oh great! I would like to say it's a JavaScript problem though! :D

 

<?php

foreach ($_POST as $key => $value) {
     if (strpos($key, 'name') === 0) {
          // do something
     }
     if (strpos($key, 'email') === 0) {
          // do something
     }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.