PHP : Turn checked checkboxes into list of items for database table and check boxes based on values stored in database table on page load -


I am storing the contents in a database table. A table column is called attrbutes and there is a list of values ​​based on that checkbox (like: 1, 3, 5 ).

gt; pre & lt; & Lt; Input type = "checkbox" name = "attribute" value = "1" & gt; Attr 1 & lt; Br> & Lt; Input type = "checkbox" name = "attribute" value = "2" & gt; 2 ATR & lt; Br> & Lt; Input type = "checkbox" name = "attribute" value = "3" & gt; Attr 3 & lt; Br> & Lt; Input type = "checkbox" name = "attribute" value = "4" & gt; 4 atr & lt; Br> & Lt; Input type = "checkbox" name = "attribute" value = "5" & gt; Attr 5 & lt; Br> & Lt; Form & gt;

Some questions on how to integrate checkboxes with PHP ...

1) How do I see if at least 1 checkbox is checked on the form?

2) How do I change the checked checkbox in the list such as 1, 3, 5 , if the checkbox 1, 3, and 5 are selected. 3) As the reverse for # 2, on page load, I have to figure out how to check each checkbox, which is the value listed in the database column. If the 1, 3, 5 table is listed in the column, then I need a check box on 1 3 and 5 page loads.

I know that how to code basic questions to insert, updating, and removing etc. ... but I have never worked with the checkbox and using php Values ​​are stored from checkboxes.

You change the html:

  & lt; Input type = "checkbox" name = "attribute []" value = "1" & gt; Attr 1 & lt; Br> & Lt; Input type = "checkbox" name = "attribute []" value = "2" & gt; Attr 2 & lt; Br> & Lt; Input type = "checkbox" name = "attribute []" value = "3" & gt; Attr 3 & lt; Br> & Lt; Input type = "checkbox" name = "attribute []" value = "4" & gt; Attr 4 & lt; Br> & Lt; Input type = "checkbox" name = "attribute []" value = "5" & gt; Attr 5 & lt; Br>  

1)

  $ checkered entry = $ _POST ['attribute']; If (counted ($ checked attree)), "At least one checkbox is selected";  

2)

  $ checkboxList = implode (',', $ checkedAttr);  

3)

$ checked = explosion (',', $ yourQueryResultStringContainingTheCheckedList); & Lt; Input type = "checkbox" name = "attribute []" value = "1" & lt ?? Php if (in_array ('1', $ checked at)) 'checked = \ "checked \"'; ? & Gt; Entry 1 & lt; Br> ...

Comments