Is "question1" (et al.) a text box where the user is supplying the question, or are those questions predetermined and you're only recording the responses?
The reason I'm asking is that unchecked checkboxes aren't submitted at all. So, no matter how you name the checkboxes, you're going to end up with information like "boxes #2, 4, and 7 were checked" - you won't know which ones were unchecked unless you have some way of determining/storing how many (and/or which ones) were displayed in the first place.
Without more information, my guess is that you'd want to name your checkboxes something like "answer[]" or perhaps "answer[123]" (where 123 is some primary/candidate key to identify which "question" is being answered). That way, $_POST['answer'] would be an array that you could use to insert whatever data is appropriate into your DB.
The questions are predefinded, I just need to record the checked box, if not checked it would recorded as a zero in the table. But because the questions (rows) that appear in the form are pulled from table 1 and displayed in a repeat region I was not too sure how I should approach the coding. But now you have pointed me in a direction by using the checkbox name as answer[] I think I can work with that. I'll keep you posted.
Many thanks
Kind regards, keep safe and well.
Dereck.
Better three hours too soon than a minute too late.
If it's good to go, be sure to mark it resolved.
It's at the top of the page under "Thread Tools"
In the form I now have the question named as "question[]" and the checkbox as "answer[]".
If I select the first and last checkbox the result is not right.
The 1st item in the answer array is answer[0]:1, checkbox checked. The 2nd item in the answer array, answer[1] is also 1, checkbox not checked.
The 20th item is checked but answer[19] displays as 0.
I hope this makes sense.
Kind regards, keep safe and well.
Dereck.
Better three hours too soon than a minute too late.
If it's good to go, be sure to mark it resolved.
It's at the top of the page under "Thread Tools"
Yes, that's as expected. As I said before, unchecked checkboxes aren't submitted, so you won't have any idea which one(s) was/were checked unless you add a unique ID inside of the [] brackets or give each checkbox a unique value.
If the checkboxs are generated from a table row within a repeat regionof the form, the form only has one checkbox before it is run in a browser. So how do I give it a unique ID?
Kind regards, keep safe and well.
Dereck.
Better three hours too soon than a minute too late.
If it's good to go, be sure to mark it resolved.
It's at the top of the page under "Thread Tools"
} while ($row_InspectItems = mysql_fetch_assoc($InspectItems));
So why not use AuditItemNo or RecordID in the value of the checkbox rather than the meaningless value "1" ?
Also, you should remove all of those 'id' attributes or fix their values. An "id" value has to be unique throughout the entire document, so using a static value inside of a loop doesn't make any sense.
Likewise, the hidden input element seems useless as well unless every row in the result set contains the same value in the RecordID column (in which case it doesn't make any sense to be outputting it inside of the loop).
Bookmarks