title: How to retrieve checkbox value from database in PHP
body: <p>My question is how to retrieve a checkbox value from the database in PHP. The below code is not working.</p>
  
  <pre><code>&lt;td&gt;Hobby&lt;/td&gt;
  &lt;?php
      $result = mysqli_query($con,"SELECT hobby FROM simple WHERE id = id"); 
      while($row = mysqli_fetch_array($result))
      {
          $focus = explode(",", $row['hobby']);
  ?&gt;    
  &lt;td&gt;
      &lt;input type="checkbox"  name="hobby[]"  value="Cricket"  size="17"   &lt;?php if(in_array("Cricket",$hobby)) { ?&gt; checked="checked" &lt;?php } ?&gt; &gt;Cricket
      &lt;input type="checkbox" name="hobby[]"  value="Music" size="17" &lt;?php if(in_array("Music",$hobby)) { ?&gt; checked="checked" &lt;?php } ?&gt; &gt;Music
      &lt;input type="checkbox" name="hobby[]"  value="Reading"   size="17" &lt;?php if(in_array("Reading",$hobby)) { ?&gt; checked="checked" &lt;?php } ?&gt; &gt;Reading
      &lt;input type="checkbox" name="hobby[]"  value="Study" size="17" &lt;?php if(in_array("Study",$hobby)) { ?&gt; checked="checked" &lt;?php } ?&gt; &gt;Study&lt;/td&gt;
  &lt;?php
     }
  ?&gt;
  &lt;/tr&gt;
  </code></pre>