title: How to insert checkbox selected values in to mysql
body: <p>I have a simple form as follows,</p>
  <pre><code>&lt;div id=&quot;new_data_Modal&quot; class=&quot;modal fade&quot;&gt;
   &lt;div class=&quot;modal-dialog&quot;&gt;
    &lt;div class=&quot;modal-content&quot;&gt;
     &lt;div class=&quot;modal-header&quot;&gt;
      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot;&gt;&amp;times;&lt;/button&gt;
      &lt;h4 class=&quot;modal-title&quot;  &gt;Update Profile&lt;/h4&gt;
     &lt;/div&gt;
     &lt;div class=&quot;modal-body&quot;&gt;
      &lt;form method=&quot;post&quot; id=&quot;update_form&quot;&gt;
       &lt;label&gt;Username&lt;/label&gt;
       &lt;input type=&quot;text&quot; name=&quot;user_name_update&quot; id=&quot;user_name_update&quot; class=&quot;form-control&quot; readonly/&gt;
       &lt;br /&gt;
       
       &lt;label&gt;Access Locations &lt;/label&gt;
       &lt;br /&gt;
  
  
       &lt;input type=&quot;checkbox&quot; name=&quot;chk[]&quot; id=&quot;chk[]&quot; value=&quot;val1&quot; /&gt; val1
       &lt;input type=&quot;checkbox&quot; name=&quot;chk[]&quot; id=&quot;chk[]&quot; value=&quot;val2&quot; /&gt; val2
       &lt;input type=&quot;checkbox&quot; name=&quot;chk[]&quot; id=&quot;chk[]&quot; value=&quot;val3&quot; /&gt; val3
       &lt;input type=&quot;checkbox&quot; name=&quot;chk[]&quot; id=&quot;chk[]&quot; value=&quot;val4&quot; /&gt; val4
  
       &lt;br /&gt;
      
       &lt;input type=&quot;hidden&quot; name=&quot;employee_id_update&quot; id=&quot;employee_id_update&quot; /&gt;
       &lt;input type=&quot;submit&quot; name=&quot;insert&quot; id=&quot;insert&quot; value=&quot;Update&quot; class=&quot;btn btn-success&quot; /&gt;
  
      &lt;/form&gt;
     &lt;/div&gt;
     &lt;div class=&quot;modal-footer&quot;&gt;
      &lt;button type=&quot;button&quot; class=&quot;btn btn-default&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
     &lt;/div&gt;
    &lt;/div&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I am using jquery to insert the values to my database.</p>
  <pre><code>$('#update_form').on(&quot;submit&quot;, function(event){  
             event.preventDefault();  
               if($('input[name=&quot;chk[]&quot;]:checked').length &gt; 0){
  
              $.ajax({  
                       url:&quot;./project/update.php&quot;,  
                       method:&quot;POST&quot;,  
                       data:$('#update_form').serialize(),  
                       beforeSend:function(){  
                            $('#insert').val(&quot;Inserting&quot;);  
                       },  
                       success:function(data){  
                            $('#update_form')[0].reset();  
                            $('#new_data_Modal').modal('hide');  
                            $('#employee_table').html(data);  
                       }  
                  
                  });  
             }
             else{
              alert(&quot;At least one checkbox should be select..&quot;); 
             }
             {  
             }  
        
  
            });
  </code></pre>
  <p>At least one of the values should be selected. I need to insert those selected checkbox values to a mysql database. As an example, lets say someone choosed val1 and val2 , I need to insert it as <code>val1,val2</code> in to <code>accesslocation</code> column in my user database.</p>
  <p>Here is my <code>update.php</code> as well.</p>
  <pre><code>&lt;?php 
  $connect = mysqli_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;, &quot;project&quot;);  
  
  if(!empty($_POST))  
   {  
        $output = '';  
        $message = ''; 
         
        $check_locations= //what should be there?
        
             $query = &quot;  
             UPDATE users   
             SET accesslocations='$check_locations'    
             WHERE username='$user_name'&quot;;  
             
             $message = 'Data updated..';
         
        if(mysqli_query($connect, $query))  
        {  
             $output .= '&lt;label class=&quot;text-success&quot;&gt;' . $message . '&lt;/label&gt;';
             echo '&lt;script type=&quot;text/JavaScript&quot;&gt; location.reload(); &lt;/script&gt;';  
             
        }  
        
        
   }  
   ?&gt;
  </code></pre>
  <p>Can someone help me do achieve this? It would be great if you could provide mysqli prepared statements as well.</p>