title: Update Mysql Records Onclick Bootrstrap Checkbox Toggle
body: <p>I want to edit status field for selected column onclick of bootstrap checkbox toggle.....Please Help 
  <strong>Example :</strong> 
  <strong>1</strong>. if status is active then when user click then it should be update in database as inactive and reload page.
  <strong>2</strong>. if status is inactive then when user click then it should be update in database as active and reload page.</p>
  
  <p><a href="https://i.stack.imgur.com/Cz4UP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cz4UP.png" alt="enter image description here"></a></p>
  
  <p><strong>Fetch Database</strong></p>
  
  <pre><code>&lt;?php 
  
  require_once 'db_config.php';
  
  $output = array('data' =&gt; array());
  
  
  // do not fetch status 3 because it is deleted
  $sql = "SELECT *,emailnotificationstable.id as sid FROM notificationslist";
  $query = $connect-&gt;query($sql);
  
  $num_rows = mysqli_num_rows($query);
  
  $x = $num_rows;
  while ($row = $query-&gt;fetch_assoc()) {
      // activate button
      $activateButton = '';
      if ($row['status'] == 1) {
              $activateButton = 
              '&lt;input type="checkbox" id="toggleBtn" name="toggleBtn" checked data-toggle="toggle" data-on="Active" data-off="Inactive" data-onstyle="success" data-offstyle="danger" data-size="mini" value="'.$row['sid'].'" onclick="editMember()"&gt;';
      } elseif ($row['status'] == 2) {
              $activateButton = 
              '&lt;input type="checkbox" id="toggleBtn" name="toggleBtn" data-toggle="toggle" data-on="Active" data-off="Inactive" data-onstyle="success" data-offstyle="danger" data-size="mini" value="'.$row['sid'].'" onclick="editMember()"&gt;';
      }
  
      // extra code here
  
      $output['data'][] = array(
          $x,
          $activateButton,
          $row['date'],
          $row['notificationname'],
          $row['employeename'],
          $createdby,
          $editedby,
          $editeddate,
          $deleteButton,
  
      );
  
      $x--;
  }
  
  // database connection close
  $connect-&gt;close();
  
  echo json_encode($output);
  </code></pre>
  
  <p><strong>Jquery</strong></p>
  
  <pre><code>// global the manage memeber table 
  var mytable;
  
  $(document).ready(function() {
      mytable = $("#mytable").DataTable({
          "ajax": "../pages/php_action/salesexe/retriveemailnotifications.php",
          "order": [],
  "fnDrawCallback": function() {
      jQuery('#mytable #adBtn').bootstrapToggle();
  }
          });
  
  
  
  });
  
  
  
  function editMember(sid = null) {
      if(sid) {
  
      // remove the error 
      $(".form-group").removeClass('has-error').removeClass('has-success');
      $(".text-danger").remove();
      // empty the message div
      $(".edit-messages").html("");
  
      // remove the id
      $("#membersid").remove();
      // click on toggle button
      $("#adBtn").click(function() {
  
          $.ajax({
              url: 'notifstatus.php',
              type: 'post',
              data: {membersid : sid},
              dataType: 'json',
              success:function(response) {
  
                  if(response.success == true) {                      
                      $(".removeMessages").html('&lt;div class="alert alert-success alert-dismissible" role="alert"&gt;'+
                            '&lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;'+
                            '&lt;strong&gt; &lt;span class="glyphicon glyphicon-ok-sign"&gt;&lt;/span&gt; &lt;/strong&gt;'+response.messages+
                          '&lt;/div&gt;');
                      // refresh the table
                      mytable.ajax.reload(null, false);
  
                  } else {
                      $(".removeMessages").html('&lt;div class="alert alert-warning alert-dismissible" role="alert"&gt;'+
                            '&lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;'+
                            '&lt;strong&gt; &lt;span class="glyphicon glyphicon-exclamation-sign"&gt;&lt;/span&gt; &lt;/strong&gt;'+response.messages+
                          '&lt;/div&gt;');
                  }
              }
          });
      }); // click toggle btn
  } else {
      alert('Error: Refresh the page again');
  }
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>&lt;?php 
  
  require_once 'db_config.php';
  
  $output = array('success' =&gt; false, 'messages' =&gt; array());
  
  $membersId = $_POST['membersid'];
  
  // update record to inactive
  $sql = "UPDATE notificationslist SET notfistatus = '2' WHERE id = $membersId";
  
  $query = $connect-&gt;query($sql);
  
  if($query === TRUE) {
      $output['success'] = true;
      $output['messages'] = 'Notification trigger successfullt activated for selected user';
  } else {
      $output['success'] = false;
      $output['messages'] = 'Error while activating notification trigger for selected user,';
  }
  // close database connection
  $connect-&gt;close();
  
  echo json_encode($output);
  </code></pre>