title: How to Set the default value to "checked" in a Checkbox from a database
body: <p>In short form, users have checkbox values stored in a MySQL database.  I can loop through the database to display the VALUES (Skills_ID + Skills_Name) for each checkbox so the user can add their skills; however, I'm not able to populate these checkboxes with the default value marked "checked" for those skills already in the database.  </p>
  
  <p>A box full of karma for anyone who can help me get to bed tonight.  :)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>     function isChecked() {
              $query = "select * FROM individual_skills WHERE Ind_ID = ".$_SESSION['Ind_ID']. "";
              $result = mysql_query($query) or die(mysql_error());        
              while($row = mysql_fetch_array($result))
              {
                  // If value exists, set $valueExitsInDB to true
                  if (isset($row['Skills_ID'])) {
                      $valueExitsInDB="TRUE";
                  } else {
                      $valueExitsInDB="FALSE";
                  }
                      // if the value does exist, then we are writing 'checked' in the checkbox       
                      if ($valueExitsInDB) {
                          return "checked";
                      } else {
                          return "";
                      }
              } // END WHILE LOOP
          } // END FUNCTION
  </code></pre>
  
  <p>And, my code within the checkbox loop looks like this (no need to burden you with reading the loop as I can safely pull the checkbox values to the output -- just not the default value):</p>
  
  <pre><code>  echo "&lt;input type='checkbox' name='skills[]' value='$skill_ID' checked='isChecked()'&gt;". $skillName ."";
  </code></pre>
  
  <p>So, you can see, I'm calling the function with:  isChecked().</p>
  
  <p>Any, and all help, very much appreciated.</p>