title: Inserting multiple checkbox values into a single SQL database column
body: <p>I'm looking for a simple solution to inserting multiple checkbox selections into a single database column. User selects box 1, 4 and 6 - so the database would reflect "1, 4, 6".. the commas would be nice but are not neccessary. If one checkbox is selected, the information will insert as it should. If multiple are selected, only the last one will be inserted into the DB. Everything else is working fine, but these darned checkboxes. I tried to use</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['mode'])) {
      $mode = implode(",", $_POST['mode']);   
  } else {
      $mode = "";
  }
  ?&gt;
  
  &lt;?php
  </code></pre>
  
  <p>as suggested by another for someone asking the same question, though this method leaves me with "Array" inside of the column instead of any numbers no matter what is selected.</p>
  
  <p>I tried to post some pictures to better explain, but it will not allow me. I'm no SQL or PHP professional, just trying to learn as much as I need to get this database going fairly quickly. If there is a solution to this issue, please enlighten me.</p>
  
  <p>Here is the code I am using for the action script on submit:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['mode'])) {
  $mode = implode(",", $_POST['mode']);   
  } else {
  $mode = "";
  }
  ?&gt;
  
  &lt;?php
  
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // Get values from form 
  $gamename=$_POST['gamename'];
  $region=$_POST['region'];
  $mode=$_POST['mode'];
  $notes=$_POST['notes'];
  
  // Insert data into mysql
  $sql="INSERT INTO $tbl_name(gamename, region, mode, notes)VALUES('$gamename', '$region', '$mode', '$notes')";
  $result=mysql_query($sql);
  
  // if successfully insert data into database, displays message "Successful". 
  if($result){
  echo "Successful";
  echo "&lt;BR&gt;";
  echo "&lt;a href='insert.php'&gt;Back to main page&lt;/a&gt;";
  }
  
  else {
  echo "ERROR";
  }
  ?&gt; 
  
  &lt;?php 
  // close connection 
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>And here is the code for my check boxes:</p>
  
  <pre><code>&lt;td&gt;&lt;input type="checkbox" name="mode[]" id="mode" value="1" /&gt;
   mode 1&lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="2" /&gt;
    mode 2&lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="3" /&gt;
    mode 3&lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="4" /&gt;
    mode 4 &lt;br /&gt; 
  &lt;input type="checkbox" name="mode[]" id="mode" value="5" /&gt;
    mode 5 &lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="6" /&gt;
    mode 6 &lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="7" /&gt;
    mode 7&lt;br /&gt;
  &lt;input type="checkbox" name="mode[]" id="mode" value="8" /&gt;
    mode 8
    &lt;/td&gt;
  </code></pre>
  
  <p>As a side note, what steps should I take to ensure my DB and website are not vulnerable to simple exploits. I plan for these forms to be used by the public to openly submit information to the database.</p>