Forum Moderators: coopster

Message Too Old, No Replies

$ Post values question

         

Sandro87

1:06 am on Jun 1, 2009 (gmt 0)

10+ Year Member



Hello,
let's say I have a form with different values that will be written in a mysql db. DVD: I have to add title, actors, date and languages. The last one is a mix of multiple values coming from the form that should be written in db column like : english,italian,spanish,french. The languages come from different inputs from the form that have name like lang1, lang2. How can I get only the langx values from $_POST and save them in an array? I could do a for each $_POST but it will get me all the $_POSTs sent like title, actors....I just want the langx inputs?

Is there a way? Or maybe is there a php fuction that can only use $_POSTs that starts with "lang" so I'm sure to use only those?

[edited by: Sandro87 at 1:09 am (utc) on June 1, 2009]

idfer

4:13 am on Jun 1, 2009 (gmt 0)

10+ Year Member



If you add a "[]" to the end of your form element names, the values are stored in an array within $_POST, e.g. if in your form you do:

<input type="text" name="lang[]" ...>
<input type="text" name="lang[]" ...>
<input type="text" name="lang[]" ...>

in PHP, you can access these values as $_POST['lang'][0], $_POST['lang'][1], etc. or foreach($_POST['lang'] as $lang) { ... }

More info in the faq: [php.net...] Hope this helps

Sandro87

10:55 am on Jun 1, 2009 (gmt 0)

10+ Year Member



Thanks! I'll give it a try!