1

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

2
  • 1
    Your statement "the serialize string will be inserted in a mySQL database" is concerning. You don't mean you're going to have a varchar or text column that simply stores the serialized string, right? Each checkbox will really be its own independent column, right? Commented Apr 14, 2010 at 17:32
  • hum. that's what I meant, actually. that the serialized string will be stored in a varchar-column. is it better if I have one column for each checkbox..? Commented Apr 16, 2010 at 22:42

1 Answer 1

2
  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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.