-3

I'm looking for the best method to input my checkbox values to the database.

The checkbox form looks like this:

         Status : custom1      custom2         custom3       custom4

value1              x             o               o             o

value2              o             x               x             x

The X and O are checkboxes. On the left side i have 5 of them right side 4 each value. I want this to be stored in the database but i don't know how to keep it simple and clean.

Marvinoo_
  • 89
  • 1
  • 2
  • 9
  • this makes no sense, you can either use `AJAX` for real time forms or you can use a submit with a `method` of `POST` and then catch the submitted data with `$_POST['name'];` – Jaquarh Mar 08 '16 at 10:30
  • Yes i can catch the submitted data with $_POST but the question is how do i set this up in my database table? i want them to stay checked when i checked them. so value 1 or 0 but i don't want to create a row for each name and each value.. How do i make this as clean as posbible with less tables? – Marvinoo_ Mar 08 '16 at 10:33
  • You haven't stated what they correspond to, you have just told us that you have a checkbox... so how can you expect anyone to be able to set-up **your** database for you? – Jaquarh Mar 08 '16 at 10:34
  • You should check bitmask http://stackoverflow.com/questions/5319475/bitmask-in-php-for-settings?rq=1 – kaklon Mar 08 '16 at 10:36

1 Answers1

0

Add array on input line like:

<input type="checkbox" name="ck[]">

And when you POST that value, you can store as

$array=$_POST['ck'];
$str=implode(",",$array);
insert into tbl (field_name) values ('$str');

By this, You can store selected checkbox's values in database as a string.

Jay Doshi
  • 666
  • 1
  • 5
  • 16