1

I'm stuck with the following:
I have 2 rows of checkboxes with different names.
HMTL Example:

<form action="" method="POST" enctype="multipart/form-data"> 
    <div id="firstrow"> 
        <input type="checkbox" name="first" value="1">1 
        <input type="checkbox" name="first" value="2">2
        <input type="checkbox" name="first" value="3">3
        <input type="checkbox" name="first" value="4">4
     </div>
     <div id="secondrow"> 
        <input type="checkbox" name="second" value="1">1 
        <input type="checkbox" name="second" value="2">2
        <input type="checkbox" name="second" value="3">3
        <input type="checkbox" name="second" value="4">4
     </div>
 </form>

The user is only allowed to select 2 checkboxes per row of checkboxes (I found a small JS code that allows me to do this).
In total they will have selected 4 checkboxes, now I want to enter all 4 of these values in to a database in separate columns.
Now I have looked up ways to convert these values in to variables, I came across one which looped a little script that checked if each checkbox was checked or not, but in the end none of all that worked the way I wanted it to.
At the moment I'm completely stuck at this point, but I'm sure there might be a somewhat easy solution to this problem that I'm completely looking over!
Now I'm asking if anybody can help me with a couple of tips or perhaps a few search terms that I could try to get me going on this problem again.

Thanks a lot in advance!
If you need more information on this problem please ask!

Mark Vonk
  • 125
  • 1
  • 1
  • 7

1 Answers1

1

Put square brackets around the name (so first[] and second[]) and you'll have all the checked boxes at your disposal in the $_POST-array (an array for each set of checkboxes).

Sherlock
  • 7,525
  • 6
  • 38
  • 79
  • Thanks a lot for your answer, I will look in to this method and let you know if it worked out! – Mark Vonk Jan 19 '15 at 15:59
  • 1
    Thanks a lot for your help Sherlock. In combination with this post: [link](http://stackoverflow.com/questions/2268887/how-do-i-see-which-checkbox-is-checked) and your suggestion I was able to achieve what I was aiming for! – Mark Vonk Jan 20 '15 at 11:15