title: How to update Database while checking checkbox with jquery?
body: <p>I am trying to update a value in DB while checking checkbox (1 or 0) with jquerys $.post or $.ajax. I would really appreciate some help. Here is my code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div class="onoffswitch"&gt;
       &lt;?php
      $yesno = (bool)$baner['noti'];
      $checked = ($yesno) ? 'checked="checked"' : '';  
       ?&gt;
     &lt;input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" value="1" id="myonoffswitch" &lt;?php echo $checked; ?&gt;&gt;
     &lt;label class="onoffswitch-label" for="myonoffswitch"&gt;&lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$(function(){
      $("#myonoffswitch").click(function(){
          $.post("notification.php");
          })
      });
  </code></pre>
  
  <p><strong>notification.php</strong></p>
  
  <pre><code>connections stuffs...
  
  $yesno = ( isset($_POST['onoffswitch']) ) ? 1 : 0;
  $sql = "UPDATE baner SET noti='$yesno'";
  </code></pre>