Forum Moderators: coopster
I'm struggling with getting checkbox results from a form into a MySQL database.
I think the following things are issues:
- what values to allow in the relevant fields in the database
- what values to give the checkboxes
- do I need an array for my checkboxes
- how to handle checkboxes that aren't checked - seems to give 'undefined index' error
This is what I have so far
- in my form, my set of checkboxes:
<input type="checkbox" name="GardenersWorld" value="GardenersWorld">Gardeners World</input><br>
<input type="checkbox" name="OrganicGardening" value="OrganicGardening">Organic Gardening</input><br>
<input type="checkbox" name="GrowYourOwn" value="GrowYourOwn">Grow Your Own</input><br>
- in my database the relevant fields are:
GardenersWorld enum('Y', 'N')
OrganicGardening enum('Y', 'N')
GrowYourOwn enum('Y', 'N')
So how do I get the results of checked checkboxes into my database so that checked => 'Y' and unchecked => 'N'? Or happy to change accepted database inputs.
Would really appreciate any tips.
Thank you. Katie
or a little more concise
$gw = isset($_POST['GardenersWorld'])? 'Y' : 'N';
Do that for each checkbox and build your sql with the resulting variables you create.