title: How to get values from a multiple checkbox and insert into database?
body: <p>I am working on a certain form that accepts multiple values using checkbox and I find it hard to get all the values of the checked boxes and store them into the database.</p>
  
  <p>Everytime my insertion query is being executed.. the only value that is stored in the database is the last checkbox the user selects thus ignoring the others..</p>
  
  <p>here's my code:</p>
  
  <p>----form-----------------------------------------------------------------'</p>
  
  <pre><code>&lt;form name="addRes" method="post" action="addReservation_code.php"&gt;
  &lt;table&gt;
      &lt;tr&gt;&lt;td&gt;Activity Date:&lt;/td&gt;
      &lt;td&gt;&lt;select name="month"&gt;
    &lt;option value="January"&gt;January&lt;/option&gt;
    &lt;option value="February"&gt;February&lt;/option&gt;
    &lt;option value="March"&gt;March&lt;/option&gt;
  &lt;option value="April"&gt;April&lt;/option&gt;
  &lt;option value="May"&gt;May&lt;/option&gt;
  &lt;option value="June"&gt;June&lt;/option&gt;
  &lt;option value="July"&gt;July&lt;/option&gt;
  &lt;option value="August"&gt;August&lt;/option&gt;
  &lt;option value="September"&gt;September&lt;/option&gt;
  &lt;option value="October"&gt;October&lt;/option&gt;
  &lt;option value="November"&gt;November&lt;/option&gt;
  &lt;option value"December"&gt;December&lt;/option&gt;
  
  &lt;/select&gt;
  &lt;select name="day"&gt;
  &lt;?php for($ctr=1;$ctr&lt;=31;$ctr++){ ?&gt;
  &lt;option value="&lt;?php print($ctr); ?&gt;"&gt;&lt;?php print($ctr); ?&gt;&lt;/option&gt;
  &lt;?php } ?&gt;
  &lt;/select&gt; -
  &lt;select name="day2"&gt;
  &lt;?php for($ctr=1;$ctr&lt;=31;$ctr++){ ?&gt;
  &lt;option value="&lt;?php print($ctr); ?&gt;"&gt;&lt;?php print($ctr); ?&gt;&lt;/option&gt;
  &lt;?php } ?&gt;
  &lt;/select&gt;
  &lt;input type="text" name="year"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Activity Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="act_name" /&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Activity Time:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="act_time" /&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Room:&lt;/td&gt;
      &lt;td&gt;
       &lt;select name="room"&gt;
        &lt;?php 
         include 'RRSdbconnect.php';
          $query = "SELECT room_name from room";
          $result=mysql_query($query) or die('Invalid query'.mysql_error()); 
           while ($row = mysql_fetch_array($result, MYSQL_BOTH)) 
           {
            echo "&lt;option&gt;$row[room_name]";
           } 
        ?&gt;
        &lt;/option&gt;
       &lt;/select&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td&gt;Resources Needed:&lt;/td&gt;
          &lt;td&gt;&lt;input type="checkbox" name="resources" value="cpu" /&gt;CPU&lt;br /&gt;
          &lt;input type="checkbox" name="resources" value="lcd" /&gt;LCD&lt;br /&gt;
          &lt;input type="checkbox" name="resources" value="sounds" /&gt;Sounds&lt;br /&gt;
          &lt;input type="checkbox" name="resources" value="sounds" /&gt;Others, Pls. specify&lt;input type="text" name="others" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;No. of Person&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="noOfPerson"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Reserved by:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="reservedby" /&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;input type="submit" name="submit" value="Submit"/&gt;&lt;input type="reset" name="clear" value="Clear"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>------------action code----------------------------------------------------</p>
  
  <pre><code>&lt;?php
  include 'RRSdbconnect.php';
  session_start();
  
  
  $date =  $_POST['month'] . ' ' .$_POST['day']. '-' .$_POST['day2']. ', ' . $_POST['year'] ;
  $name=$_POST['act_name'];
  $time=$_POST['act_time'];
  $room=$_POST['room'];
  $resources=$_POST['resources'];
  $noOfPerson=$_POST['noOfPerson'];
  $reservedby=$_POST['reservedby'];
  
  
  //insertions for add reservations
   $query="insert into reservation (activity_date, activity_name, activity_time, room, resources_needed, no_person, reserved_by) values('$date','$name','$time','$room','$resources','$noOfPerson','$reservedby')";
   $result=mysql_query($query,$link) or die("Error!".mysql_error());  
  ?&gt;
  </code></pre>
  
  <p>PS.
   I am using checkbox on the column resources needed..</p>
  
  <p>any help will be appreciate..tnx</p>