I have a form as below which allows user to select different collar types. Each checkbox has a collar id which will be submitted when the form is submitted.
Assume that user selected 1st three collars. It would look like this.
Then what I do is add these three collar to my collars table using an insert statement. After that If user wants, he can uncheck the collar types or add new.
Assume that user unchecked the 2nd type as below.
Now the particular row which refer to the 2nd collar type must be deleted from the table. Below images shows the table structure.
Now my problem is When the form is submitted if user has made any changes(checked new checkbox or unchecked any) How can I Insert or delete a row? Do I have to write SELECT statement for each checkbox and see whether that collar id exists?
Help me out with the logic because I'm able to build the code myself according to a given logic.
Thanks