I have a HTML form where users can checkmark up to 50 different questions. They have to checkmark minimum 1 and at the most all 50 questions.
After they submit the form I need to insert the data (form_array
) to my mySQL table questions. The table contains of 50 questions rows (see below question table ex.).
I know the INSERT INTO 'questions' (question1, question2, question3, question4,....question50) VALUES (value1, value2, value3...)
, but my challenge is that since the amount of checked questions (values) can vary in the form, I do not know how to insert the form_array
to my questions table.
The questions are inserted as true or false in the form_array
depending on if they are marked or unmarked in the html form.
The questions table has a primary auto incremented ID and 2 foreign keys besides the 50 questions.
I welcome all suggestions/examples on how to insert an array with the above scenario?
The question table will look like this:
`question1` tinyint(1) NOT NULL,
`question2` tinyint(1) NOT NULL,
`question3` tinyint(1) NOT NULL,
`question4` tinyint(1) NOT NULL,
`question5` tinyint(1) NOT NULL,
`question6...etc etc...up to 50 questions