views:

312

answers:

1

Hi,

I was wondering if this is possible. The serialize-string will be inserted in a mySQL-database, so it would be fine if all checkboxes would be inserted and not only the ones that is ticked(on).

it's possible to make on column in the database for each of the checkboxes, and use this if/else-statement:

if(isset($_GET['checkbox'])) {
                  // It's checked!
         }
         else {
                  // not checked!
         }

but its a bit unappropriate...

+1  A: 
  1. Give all the checkboxes the same name (ending in [] since this is PHP)
  2. Give all the checkboxes different values
  3. Have an array of all possible values in the script (you can use the same array when generating the HTML for the form!)
  4. Loop over it and use in_array to determine if you should set it to true or false
  5. Pass the result to your database function
David Dorward