Neosocrates Posted November 30, 2010 Share Posted November 30, 2010 I have been having a bit of difficultly understanding how to submit a single checkbox values for a list of names and saving it in a MySQL database. The way it is meant to work is that a list of names from a table (Table1) is produced on the screen through a query. I have a checkbox that appears beside each individual name and if I tick the box I want it to save the value '1' to the database, otherwise the value remains as zero. When I tick the necessary boxes I wish to save it to another table (Table2, it is separate from Table1). The name and value needs to be saved to it. The problems that arises is how do I save the checkbox value for each individual name? Will I need to use a checkbox array or can I treat each name as independent? Hopefully you understand what I mean. Quote Link to comment Share on other sites More sharing options...
JakeTheSnake3.0 Posted November 30, 2010 Share Posted November 30, 2010 I think you need to clarify what you're using the two tables for. It sounds like they hold the exact same information. If your question has to do with accessing the values of each checkbox after a form was submitted, use an array name under the checkbox "name" attribute. Example below: <input type="checkbox" name="name_id[]" value="1" /> <input type="checkbox" name="name_id[]" value="2" /> name_id will be accessible as $_POST['name_id']. Only checkboxes that were checked will be put into the array; so if you've only checked the 2nd box (with value of "2"), the POST array will have one element with a value of 2. The value attribute for the checkbox should be the ID gathered from the database. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.