title: Dreamweaver multiple checkbox selection then insert to MySQL
body: <p>I have an order form and the products are in checkboxes. The selected items should be inserted to a database column. I'm not very good in coding yet so it would be great if you showed me an example. Thank you.</p>
  
  <p>Here's my table:</p>
  
  <pre><code>&lt;form name="form" method="POST"&gt;
      &lt;table width="623" height="283" border="0" align="center"&gt;
  &lt;tr&gt;
  &lt;td width="146"&gt;Name:&lt;/td&gt;
  &lt;td width="266"&gt;&lt;label for="name"&gt;&lt;/label&gt;
    &lt;input type="text" name="name" id="name" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Contact No:&lt;/td&gt;
  &lt;td&gt;&lt;label for="contactno"&gt;&lt;/label&gt;
    &lt;input type="text" name="contactno" id="contactno" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Address:&lt;/td&gt;
  &lt;td&gt;&lt;label for="address"&gt;&lt;/label&gt;
    &lt;input type="text" name="address" id="address" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td height="31"&gt;Select Items:&lt;/td&gt;
  &lt;td&gt;
      &lt;label&gt;
        &lt;input type="checkbox" name="CheckboxGroup[]" value="sample one" id="CheckboxGroup_0" /&gt;
        Checkbox&lt;/label&gt;
      &lt;br /&gt;
      &lt;label&gt;
        &lt;input type="checkbox" name="CheckboxGroup[]" value="sample two" id="CheckboxGroup_1" /&gt;
        Sample&lt;/label&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  &lt;/p&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Payment Option:&lt;/td&gt;
  &lt;td&gt;
    &lt;label for="pay_option"&gt;&lt;/label&gt;
    &lt;select name="pay_option" id="pay_option"&gt;
      &lt;option value="Counter"&gt;Counter&lt;/option&gt;
      &lt;option value="BDO"&gt;BDO&lt;/option&gt;
      &lt;option value="Smart Money"&gt;Smart Money&lt;/option&gt;
    &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Claiming Option:&lt;/td&gt;
  &lt;td&gt;
    &lt;label for="claim_option"&gt;&lt;/label&gt;
    &lt;select name="claim_option" id="claim_option"&gt;
      &lt;option value="Pick-up"&gt;Pick-up&lt;/option&gt;
      &lt;option value="Shipping"&gt;Shipping&lt;/option&gt;
    &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="2" align="center"&gt;&lt;input type="submit" name="button" id="button" value="Submit" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Basically, whatever the user selects, should be inserted to a db column upon clicking the submit button. I don't know the PHP script for it.I use dreamweaver and mysql workbench</p>
  
  <p>PHP</p>
  
  <p>the code you gave me is at the very bottom. the rest are generated by DW when i did the insert record gui</p>
  
  <pre><code>&lt;?php require_once('Connections/MCC.php'); ?&gt;
  
  &lt;?php
  if (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  {
  if (PHP_VERSION &lt; 6) {
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  
  switch ($theType) {
  case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;    
  case "long":
  case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
  case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
  case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
  case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
  }
  return $theValue;
  }
  }
  
  $editFormAction = $_SERVER['PHP_SELF'];
  if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO order_form (name, address, contact_no, payment_option, claim_option, orders) VALUES (%s, %s, %s, %s, %s, %s)",
                     GetSQLValueString($_POST['name'], "text"),
                     GetSQLValueString($_POST['address'], "text"),
                     GetSQLValueString($_POST['contactno'], "text"),
                     GetSQLValueString($_POST['pay_option'], "text"),
                     GetSQLValueString($_POST['claim_option'], "text"),
                     GetSQLValueString(isset($_POST['CheckboxGroup[]']) ? "true" : "", "defined","'Y'","'N'"));
  
  mysql_select_db($database_MCC, $MCC);
  $Result1 = mysql_query($insertSQL, $MCC) or die(mysql_error());
  }
  
  //-------added this---------
  if (isset($_POST['submit']))
    {
      $implode=implode(",",$_POST['CheckboxGroup']);
      mysql_query("INSERT INTO order_form (orders) VALUES ('".$implode."')") ;
    }
  ?&gt;
  </code></pre>