title: multiple if statements used to update database entries
body: <p>Have the following code that on button click goes to database named 'colleges' where columns are named 'college1', 'college2', etc (to 'college10') as well as 'sports1', 'sports2', etc (to 'sports10')</p>
  
  <pre><code>if ($row['college4'] == null) {
       $sql = "UPDATE colleges SET college3 = NULL, sports3 = NULL";
  }
  if ($row['college3'] == null) {
       $sql = "UPDATE colleges SET college2 = NULL, sports2 = NULL";
  }
  if ($row['college2'] == null) {
       $sql = "UPDATE colleges SET college1 = NULL, sports1 = NULL";
  }
  </code></pre>
  
  <p>Essentially, if a specific column in the database equals NULL, then set the preceding column to NULL. The prior coding works, however, only for the most recent if statement (In this case, college2). Once that executes, the remaining if statements are ignored (i.e. college 4 and college 3.</p>
  
  <p>If more explanation is needed please let me know. I think I am just looking for a how to on having the sql queries recognize in a cascading manner. Thanks. </p>
  
  <p>Full PHP:</p>
  
  <pre><code>&lt;?php
              session_start();
  
              define("DB_HOST", "");
              define("DB_USER", "");
              define("DB_PASS", "");
              define("DB_NAME", "");
  
              // Create connection
              $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  
              if ($conn-&gt;connect_error) {
                  die("Connection failed: " . $conn-&gt;connect_error);
              }
  
                      if ($row['college4'] == null) {
                          $sql = "UPDATE colleges SET college3 = NULL, sports3 = NULL";
                      }
                      if ($row['college3'] == null) {
                          $sql = "UPDATE colleges SET college2 = NULL, sports2 = NULL";
                      }
                      if ($row['college2'] == null) {
                          $sql = "UPDATE colleges SET college1 = NULL, sports1 = NULL";
                      }
  
              if ($conn-&gt;query($sql) === TRUE) {
                  echo "Record deleted successfully";
              } else {
                  echo "Error deleting record: " . $conn-&gt;error;
              }
  
              mysqli_close($conn);
          ?&gt;
  </code></pre>