title: Check if a MySQL field value is equal to a certain number
body: <p>I'm new with PHP and MySql and I've searched all over the Internet but couldn't find a proper answer.</p>
  
  <p>Using PHP, I need to grab a value from a single cell of a MySQL Database and check if that value is equal to 0 or to 1.  If it's equal to 1 then set it to 0, and viceversa.</p>
  
  <p>How do I do it?  Thank you for helping!!</p>
  
  <pre><code>&lt;?php
  
  $servername = "localhost";
  $username = "username";
  $password = "";
  $dbname = "database";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  echo "Connected successfully";
  
  $sql_light = mysqli_query("SELECT light FROM bot_command WHERE cmd_id = '1'");
  $result_light = mysql_fetch_assoc($sql_light);
  
  if (isset($result_light['light']) &amp;&amp; $row['light'] == 1) {
      $sql = "UPDATE bot_command SET light='0' WHERE cmd_id = '1'";
      $result = $conn-&gt;query($sql);
      // output data of each row
      while($row = $result_select-&gt;fetch_assoc()) {
          echo " - Light: " . $row["light"]."&lt;br&gt;";       
      }
  } else {
      echo "0 results";
  }
  
  
  
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo " - Record updated successfully";
  } else {
      echo " - Error updating record: " . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  
  //$sql = "SELECT light FROM bot_command WHERE cmd_id = '1'";
  
  ?&gt;
  </code></pre>