title: Using On/Off Checkbox Sliding Switch to Run SQL Query
body: <p>I am using a simple On/Off sliding switch to update a field in my database.</p>
  
  <p>I turn it "on" no problem, but allowing the user to turn it "off" seems to be giving me trouble. I have multiple switches on this page, so whenever I "submit" it will turn "on" values to "off" unless I remove the elseif statement.</p>
  
  <p>It seems the code considers the $_POST['check-twitter'] to be "isset" when it is on, but "!isset" when I switch it from on to off. </p>
  
  <p>If I change my code to instead be "elseif(!isset....)" then when I come to the page again, it does not recognize the "on" position as being "isset" so it automatically turns it off. It seems inconsistent to what is considered "isset" and "!isset".</p>
  
  <p>I want the switch to only update the database when the user changes it, and I need the switch to show the user whether it is "on" or "off."</p>
  
  <pre><code>// $twitter_check represents the field from the database which equals 'Yes' or 'No'
  
  &lt;label class="switch"&gt;
    &lt;input type="checkbox" name="check-twitter" &lt;?php echo $twitter_check == 'Yes'?'checked':''; ?&gt;&gt;
    &lt;div class="slider"&gt;&lt;/div&gt;
  &lt;/label&gt;
  
  if(isset($_POST['check-twitter']) &amp;&amp; $twitter_check == "No"){
      //SQL UPDATE $twitter_check = 'Yes'
      } elseif(isset($_POST['check-twitter']) &amp;&amp; $twitter_check == "Yes") {
      //SQL UPDATE $twitter_check = 'No'
      }
  
  &lt;input class="button" type="submit" name="submit" value="Save"/&gt;
  </code></pre>