Jump to content


Photo

Form post, unknown number of fields to retrieve

php form post variables

  • Please log in to reply
1 reply to this topic

#1 jasonwisdom

jasonwisdom
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 April 2015 - 05:56 AM

Hi everybody!

 

I am building a custom PHP app, and am submitting a form.

This form will have between 1 or more textareas, named "textarea1", "textarea2", "textarea200", and so on.

 

I need to read each of these and insert them into a database. 

 

How can I script this into the PHP landing page?

 

Is there a way to read all of the values, and names, that are contained in $_POST.

 

Many thanks,

Jason

 



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 17,973 posts

Posted 26 April 2015 - 09:16 AM

Instead of naming them "textarea1", "textarea2" etc, name them "textarea[]" so they are posted as an array.

 

To process

foreach ($_POST['textarea'] as $text) {
    // process each $text item
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users