Problem statement:
- I have a form with multiple checkbox Fields, i have validated it so
user can select maximum 9 checkbox and atleast 1 with jquery.
- I collect the Form checked values using Post method.
first 3 columns are "id", "rollnum", "selectStatus"
Through session variables created during Login, i get roll number of student. So i can Run Update Query on particular row.
Question: How do i Update those 9 subject columns according to user checked inputs. Note : i stored those checked input field values in an array.
Code
<form action="index.php" id="form-3" method="post"> <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="ucs303">UCS303 Operating Systems <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="ucs406">UCS406 Data Structures and Algorithms <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec401">UEC401 Analog Communication Systems <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec612">UEC612 Digital System Design <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec307">UEC307 Electromagnetic Field Theory & Trans Lines <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec502">UEC502 Digital Signal Processing <input class="form-check-input" name="year-3-checkbox[]" type="checkbox" value="uec510">UEC510 Computer Architecture <button type="submit" name="year-3-submit">Submit Selection</button> </form> <?php if(isset($_POST['year-3-submit'])){ if(!empty($_POST['year-3-checkbox'])){ $subjectCheckList = array(); $subjectCheckList = $_POST['year-3-checkbox']; } } ?>
It depends on user how many checkbox is selected.
- I donot know how to write UPDATE sql query which updates values of number of columns == size of array.
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.
- I donot want to write 9 switch case statements for all possible sizes of array. Any idea? please?