title: mysql Update Statement depending on number of checkbox checked
body: <p><strong>Problem statement:</strong></p>
  
  <ul>
  <li>I have a form with multiple checkbox Fields, i have validated it so
  user can select maximum 9 checkbox and atleast 1 with jquery.
  <a href="https://i.stack.imgur.com/YEG26.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YEG26.png" alt="Form with Multiple Checkbox"></a></li>
  <li>I collect the Form checked values using Post method.</li>
  <li><p>i have mysql table with 12 columns.
  <a href="https://i.stack.imgur.com/uJnh5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uJnh5.png" alt="Mysql Table Image"></a></p></li>
  <li><p>first 3 columns are "id", "rollnum", "selectStatus"</p></li>
  <li><p>Through session variables created during Login, i get roll number of student. So i can Run Update Query on particular row.</p></li>
  <li><p><strong>Question:</strong> How do i Update those 9 subject columns according to user checked inputs. Note : i stored those checked input field values in an array.</p></li>
  <li><p><strong>Code</strong></p>
  
  <pre><code>&lt;form action="index.php" id="form-3" method="post"&gt;
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="ucs303"&gt;UCS303 Operating Systems
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="ucs406"&gt;UCS406 Data Structures and Algorithms
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec401"&gt;UEC401 Analog Communication Systems
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec612"&gt;UEC612 Digital System Design
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec307"&gt;UEC307 Electromagnetic Field Theory &amp; Trans Lines
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec502"&gt;UEC502 Digital Signal Processing
      &lt;input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec510"&gt;UEC510 Computer Architecture
      &lt;button type="submit" name="year-3-submit"&gt;Submit Selection&lt;/button&gt;
  &lt;/form&gt;
  &lt;?php
      if(isset($_POST['year-3-submit'])){
          if(!empty($_POST['year-3-checkbox'])){
              $subjectCheckList = array();
              $subjectCheckList = $_POST['year-3-checkbox'];
          }
      }
  ?&gt;
  </code></pre></li>
  <li><p>It depends on user how many checkbox is selected.</p></li>
  <li>I donot know how to write UPDATE sql query which updates values of number of columns == size of array.</li>
  </ul>
  
  <p><em>for example:
  User 1 has selected 3 checkbox and submitted form, we have array of size 3 and UPDATE 3 columns of table.
  User 1 has selected 6 checkbox and submitted form, we have array of size 6 and UPDATE 6 columns of table.</em></p>
  
  <ul>
  <li>I donot want to write 9 switch case statements for all possible sizes
  of array. Any idea? please?</li>
  </ul>