Hello guys. I have a form in which i have some dynamically generated input fields like this:

<input value="March" name="month[March]" type="hidden">
<input value="April" name="month[April]" type="hidden">
<input value="May" name="month[May]" type="hidden">
.
.
.

How do i add the input data for each month to mysql? Thanks!

Member Avatar for diafol

I can't see how this works. You don't need to have an array key if the value is equal to the month.

<input value="March" name="month[]" type="hidden">

Should be fine. Then

$montharray = (array) $_POST['month'];

You now have all the months collected into the $montharray array.

let me explain
So i have a form in which these fiels are dynamically generated by pressing a button. The generated input number is equal to the number of months between 2 dates. Foreach input the name is actually the months name. Also the value is the month name, so that i can add it in the corect db table row. The problem is that i need to know how to add each field to mysql

Member Avatar for diafol

It still makes no sense to me. You have a host of hidden inputs which don't really do anything.
Why not have just one hidden input if you really need it?

   <input value="January_March" name="range" type="hidden" />

Personally, I'd use a different format for the value (bits, e.g. 1=jan, 2 = feb, 4=mar, 8 = apr etc and total the range, e.g. 7 = jan to march or 14 = feb to apr).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.