title: Automatcially check checkbox based on database array PHP
body: <p>In the "User Setting" tab of my page, I want the user to determine which types of posts from a specific user.  Here is the form:</p>
  
  <pre><code>&lt;form method="post" action="" name="permitted_categories"&gt;
                  Select or deselect which types of Posts that you would like to see. 
                  &lt;p&gt;
                  &lt;?
                  $cat_query = mysqli_query($con, "SELECT permitcat FROM permitted WHERE username='$userLoggedIn' AND friendname='$username'")
                  ?&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="Life" id="Life" &lt;? echo $checked;?&gt;&gt;
                        Life&lt;/label&gt;
                      &lt;br&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="Politics" id="Politics" &lt;? echo $checked;?&gt;&gt;
                        Politics&lt;/label&gt;
                      &lt;br&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="Entertainment" id="Entertainment" &lt;? echo $checked;?&gt;&gt;
                        Entertainment&lt;/label&gt;
                      &lt;br&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="Food" id="Food" &lt;? echo $checked;?&gt;&gt;
                        Food&lt;/label&gt;
                      &lt;br&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="BusFin" id="BusFin" &lt;? echo $checked;?&gt;&gt;
                        Business/Financial&lt;/label&gt;
                      &lt;br&gt;
                      &lt;label&gt;
                        &lt;input type="checkbox" name="categories[]" value="Fitness" id="Fitness" &lt;? echo $checked;?&gt;&gt;
                        Fitness/Health&lt;/label&gt;
                      &lt;br&gt;
                      &lt;input type="submit" name="update_categories" id="update_categories"&gt;
                      &lt;? 
                        if(isset($_POST['update_categories'])) {
                            $permitted_categories = $_POST['categories'];
  
                            echo "You will only see the following categories from ". $profile_user_obj-&gt;getFirstAndLastName() .": ";
                            foreach ($permitted_categories as $permcat){
                              echo $permcat .", ";
                          }
  
                            $values  = implode(", ", $permitted_categories);
                            $permit_query = mysqli_query($con, "INSERT INTO permitted (id, username, friendname, permitcat) VALUES('','$userLoggedIn', '$username', '$values')");   
                          } ?&gt;
                &lt;/p&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>What I am trying to do is automatically check the boxes where the corresponding values are found in an array.</p>
  
  <p>I have tried several things, but cannot get the code to work.</p>