Jump to content

Checkbox Query


Neosocrates

Recommended Posts

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.  :shrug:

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.