title: Submit value of a checkbox via jquery/ajax to php and insert into db
body: <p>I tried to find help via the search function on here but all the answers given to similar problems were too elaborate for me to understand, i.e. the example code was too complex for me to extract the parts which could have been relevant for my problem :(</p>
  
  <p>I have a html form which sends userinput on a specific row in a datatable via an ajax-request to a php file, where the input gets inserted into my sqldb.
  I have no problem sending the textinput entered by a user and also transferring additional infos like the specific row they were on, or the network account of the user. But i now want to add a checkbox, so the users can choose whether their comment is private or public. However i somehow cannot transmit the value from the checkbox, there is no error but also no checkboxdata inserted into the db.
  Do i have to handle checkboxes differently than textareas? I'd be very grateful for help!</p>
  
  <p>My code looks as follows:
  Html:</p>
  
  <pre><code>        function insertTextarea() {
  
                          var boardInfo = $( "&lt;form id='boardComment'&gt;&lt;textarea rows='2' cols='30'&gt;Notizen? Fragen? Kommentare?&lt;/textarea&gt;Privat:&lt;input type='checkbox' name='privatcheckbox' value='private'&gt;&lt;input type='submit' value='Submit'&gt;&lt;input type='reset' value='Cancel'&gt;&lt;/form&gt;");   
  
                          $( this ).parent().append(boardInfo);
                          $("tbody img").hide();
  
                          $("#boardComment").on( "submit", function( event ) {
                              event.preventDefault(); 
                              var change_id = {};
                              change_id['id'] = $(this).parent().attr("id");
                              change_id['comment'] = $(this).find("textarea").val();
                              change_id['privatecheckbox'] = $(this).find("checkbox").val();
  
                              if( $(this).find("textarea").val() ) {
                                  $.ajax({
                                      type: "POST",
                                      url: "boardinfo.php",
                                      cache: false,
                                      data: change_id,
                                      success: function( response2 ) {
                                          alert("Your comment has been saved!");
                                          $("tbody img").show();
                                          $("#" + change_id['id']).find("form").remove();
                                      }
                                  }); 
                              };
                          });
  </code></pre>
  
  <p>and this is the php part:</p>
  
  <pre><code>$id = mysql_real_escape_string($_POST['id']);
  $comment = mysql_real_escape_string($_POST['comment']);
  $privatecheckbox = mysql_real_escape_string($_POST['privatecheckbox']);
  $sql="INSERT INTO cerberus_board_info (BOARD_INFO_COMMENTS, BOARD_INFO_USER, BOARD_INFO_CHANGE_ID, BOARD_INFO_ENTRY_CHANNEL, BOARD_INFO_PRIVACY_LEVEL) VALUES ('$comment', '$ldapdata', '$id', 'Portal', '$privatecheckbox')"; 
  </code></pre>