Copy link to clipboard
Copied
My client's site was previously setup where on the site's update page, there are a number of checkboxes.. and when the page is updated, their PHP update code would take whatever checkboxes were checked, and insert their relative default values into a single field in the mySQL table.. each separated by a comma.
For examle, of there are checkboxes named 1 and 2 and 3 and 4.. and only 1 and 4 are checked, then in the mySQL table/field, you would see this inserted:
1,4
The Dreamweaver PHP Update just inserts one value per field it looks like.. is there a way to modify it's UPDATE behavior/function so that we can accomplish this same goal?
Copy link to clipboard
Copied
When using a checkbox group or a multiple-choice list, you need to add an empty pair of square brackets after the name like this:
<input type="checkbox" name="options[]" id="options1" value="sunroof" />>
<input type="checkbox" name="options[]" id="options2" value="satnav" />
When the form is submitted, $_POST['options'] or $_GET['options'] contains an array of the selected values.
To convert the array into a comma-separated string, use implode().
implode(',', $_POST['options'])
Copy link to clipboard
Copied
Be aware that storing multiple values in a single field violates the rules of database normalization. If the data will be used in any type of analysis, you should not be storing it this way. If the data is simply saving user preferences or something similar, it's probably ok.
Copy link to clipboard
Copied
I agree... unfortunately, I didn't build the original and this is what I'm forced to work with. [sigh]
Find more inspiration, events, and resources on the new Adobe Community
Explore Now