0

I Want to insert multiple rows from a single form submission. My form looks like this.

<form method="post">
   <input name="1[name]">
   <input name="1[email]">
     
   <input name="2[name]">
   <input name="2[email]">

   <input name="3[name]">
   <input name="3[email]">

   <input name="submit" value="submit">
 </form>

How can I insert each of those items into database as individual rows?

Ezekiel Arin
  • 115
  • 6
  • Like, you want to insert those as 3 rows? – Samuel Asor Dec 12 '20 at 20:38
  • Yes but those fields will be generated dynamically – Ezekiel Arin Dec 12 '20 at 20:39
  • I still don't get it. Since it is generated dynamically, is there no way you can influence the value of the name attributes? Or better still, can you explain the use case? – Samuel Asor Dec 12 '20 at 20:48
  • 2
    Take a look at this [question](https://stackoverflow.com/questions/9073690/post-an-array-from-an-html-form-without-javascript) . They use HTML forms with arrays, so that when you get your form in the `$_POST`, you'll see an array of your elements. Then just loop through every one of them and put them to the DB. – Kipras Bielinskas Dec 12 '20 at 20:59
  • @Eze you will need to modify your field names to use array syntax. See the duplicate. Without the trailing `[]` on the the field names, each subsequent pair of fields will overwrite the previous fields value. – mickmackusa Dec 12 '20 at 22:08
  • 1
    I followed the link, it looks more like what am looking for thanks – Ezekiel Arin Dec 12 '20 at 22:14

0 Answers0