Hello,

I have an html form with a checkbox input. When I try to save the checkbox results in mysql, it does not appear. I did try serializing the checkbox arrays, but it does not work consistently.

Any way to combat this?

Thanks in advance!

    Each check box is only posted to the process script IF its checked. You could use isset() to check each checkbox individually and do logic from there to store the info.

      Derokorian;10984229 wrote:

      Each check box is only posted to the process script IF its checked. You could use isset() to check each checkbox individually and do logic from there to store the info.

      Do you mind briefly explaining what isset() does?

        isset() checks if a variable is set, useful for checking if a post or get variable is being passed. Example:

        if( isset($_GET['id']) ) {
           echo "ID set to ". $_GET['id'];
        } else {
           echo "No ID found.";
        }
        
          6 days later
          Derokorian;10984231 wrote:

          isset() checks if a variable is set, useful for checking if a post or get variable is being passed. Example:

          if( isset($_GET['id']) ) {
             echo "ID set to ". $_GET['id'];
          } else {
             echo "No ID found.";
          }
          

          the code you posted above shows up as an error when I use it 😕

            if ( isset($_POST['partnerbodytype'] ) {
                echo "ID set to". $_POST['partnerbodytype'];
                  } else {
                   echo "No ID found.";
                  }
            
            if ( isset($_POST['partnerethnicity'] ) {
                echo "ID set to". $_POST['partnerethnicity'];
                  } else {
                   echo "no ID found.";
                  }
            
            if ( isset($_POST['partnerage'] ) {
                echo "ID set to". $_POST['partnerage'];
                  } else {
                   echo "no ID found.";
                  }
            
            if ( isset($_POST['partnersgender'] ) {
                echo "ID set to". $_POST['partnersgender'];
                  } else {
                   echo "no ID found.";
                  }
            
            if ( isset($_POST['partnerorientation'] ) {
                echo "ID set to". $_POST['partnerorientation'];
                  } else {
                   echo "no ID found.";
                  }
            
            if ( isset($_POST['parnterpresentation'] ) {
                echo "ID set to". $_POST['parnterpresentation'];
                  } else {
                   echo "no ID found.";
                  }
            
            
            $partnerbodytype= serialize($_POST['partnerbodytype']);
            $partnerethnicity= serialize($_POST['partnerethnicity']);
            $$partnersage= serialize($_POST['partnersage']);
            $partnersgender= serialize($_POST['partnersgender']);
            $partnersorientation= serialize($_POST['partnersorientation']);
            $partnerspresentation= serialize($_POST['parnterspresentation']);

              wondering why the serialization is needed. Could you post the INSERT part?

                Also if you don't need the echo's to see what things are set to (which I'm thinking you don't since you didn't change the text, you could use Ternary to get it out of POST data. As such:

                $partner = array();
                $partner['bodytype'] = isset($_POST['partnerbodytype']) ? trim($_POST['partnerbodytype']) : NULL;
                $partner['age'] = isset($_POST['partnerage']) ? $_POST['partnerage'] : NULL;
                // .. etc etc
                $missingfields = FALSE;
                foreach($partner as $field) {
                   if( isnull($field) )
                      $missingfields = TRUE;
                }
                
                if( $missingfields ) {
                  /// display form again
                } else {
                   /// process form
                }
                
                  anoopmail;10984561 wrote:

                  wondering why the serialization is needed. Could you post the INSERT part?

                  I have to serialize certain $_POST because the html form I am getting the information is a checkbox question. Do you know how I can store the answers to the checkbox information into a mysql table?

                    Derokorian;10984597 wrote:

                    Also if you don't need the echo's to see what things are set to (which I'm thinking you don't since you didn't change the text, you could use Ternary to get it out of POST data. As such:

                    $partner = array();
                    $partner['bodytype'] = isset($_POST['partnerbodytype']) ? trim($_POST['partnerbodytype']) : NULL;
                    $partner['age'] = isset($_POST['partnerage']) ? $_POST['partnerage'] : NULL;
                    // .. etc etc
                    $missingfields = FALSE;
                    foreach($partner as $field) {
                       if( isnull($field) )
                          $missingfields = TRUE;
                    }
                    
                    if( $missingfields ) {
                      /// display form again
                    } else {
                       /// process form
                    }
                    

                    I'm a little perplexed as to what exactly isset() does. Does it store the data into mysql?

                      I linked the manual, explained it and gave examples.... it returns true if the variable IS SET, and false if it IS NOT SET. What more can I tell you....

                        Write a Reply...