title: Update DB value using switch element
body: <p>I have an html switch to toggle between <code>on</code> and <code>off</code>:</p>
  
  <pre><code>&lt;label class="switch"&gt;
      &lt;input type="checkbox" id="togBtn" name="active" checked="checked"&gt;
      &lt;div class="slider round"&gt;
          &lt;span class="on"&gt;ON&lt;/span&gt;
          &lt;span class="off"&gt;OFF&lt;/span&gt;
      &lt;/div&gt;
  &lt;/label&gt;
  </code></pre>
  
  <p>You can check it live here: <a href="http://jsfiddle.net/tc4byzo8" rel="nofollow noreferrer">http://jsfiddle.net/tc4byzo8</a></p>
  
  <p>It's checked by default <code>on</code>and it's inside a form:</p>
  
  <pre><code>&lt;form method="post"&gt;
      ..
      &lt;input type="submit" name="submit" value="Submit" &gt;
  &lt;form&gt;
  </code></pre>
  
  <p>When the <code>Submit</code> button is clicked, I insert the data into the DB:</p>
  
  <pre><code>//Check if submit button is clicked.
  if( isset($_POST['submit']) ){
  
       //Insert the data into the DB.
      $stmt = $conn-&gt;prepare( /* Insert query */ );
      $stmt-&gt;execute();
  
  }
  </code></pre>
  
  <p>The DB has column which values could be <code>1</code> or <code>0</code>, So if the checkbox is checked, the value would be <code>1</code>.</p>
  
  <p>How to check if the checkbox is checked or not to insert the values <code>1</code> or <code>2</code>?</p>
  
  <p>I added the attribute <code>checked="checked"</code>, So that it's checked by default, But when I switch it off, The <code>checked</code> attribute still there.</p>