Page 1 of 1

Question on working with checkboxes, PHP, and SQL

Posted: Mon Jun 30, 2008 9:40 am
by dpechacek
Hello. New member with a question. I'm also somewhat limited with my PHP skills since I'm fairly new to it.

What we're doing is we are dynamically generating forms (both in a form look and a table look) using PHP and drawing from a MySQL database. The problem I'm having is that some of the fields of the forms/tables are checkboxes. And I don't know how to properly parse the data when the form is submitting and needing to be updated.

We are submitting with POST. Currently each row of a table is given a unique name, then the field name, row number, and then for sets, _set_<value>. That way each checkbox has a unique name. What I don't know is that when the data is submitted, for boxes that used to be checked an no longer are, I need to delete the row associated with that check box. For each new row for each newly selected checkbox, create it. And updating rows for checkboxes that were already checked.

Currently we loop through the number of rows in the table adding, updating, and deleting but obviously that doesn't work since then you'll only get the first checkbox that is checked.

Are there any existing libraries of code to deal with dynamically generated forms? Any ideas?