March 25, 2012
php add inputs with same name to mysql
Question by gogu
I have a form with some generated input fields like theese:
<input value="March" name="month[March]" type="hidden">
<input value="April" name="month[April]" type="hidden">
<input value="May" name="month[May]" type="hidden">
I need to add the data from each input to mysql, but i don`t know how if they have name[monthname].The table structure is id, name and month_name. So i need to add the input data to month_name column. Thanks!
Answer by Starx
You can iterate over different input with same name in this way
foreach($_POST['month'] as $value) {
echo $value;
//Use the value in the query, it gets April March may, one by one
}
P.S: Assuming you are using POST method to submit the form.