title: PHP MYSQL Insert dynamic array into database
body: <p>The dynamic HTML form (with some js help) and PHP script below insert user entered values into MySQL successfully, except that all rows from the form are placed in one row on the database. What am I doing wrong?</p>
  
  <p>Dynamic form HTML:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;table id="dataTable" class="form" border="4"&gt;
      &lt;tbody  style="font-size:8pt"&gt;
      &lt;th&gt;
          &lt;td align="center"&gt;Company&lt;/td&gt;
          &lt;td align="center"&gt;Project&lt;/td&gt;
          &lt;td align="center"&gt;Sub-Project&lt;/td&gt;
          &lt;td align="center"&gt;Change From&lt;/td&gt;
          &lt;td align="center"&gt;Change To&lt;/td&gt;
          &lt;td align="center"&gt;Activity&lt;/td&gt;
          &lt;td align="center"&gt;Responsible&lt;/td&gt;
          &lt;td align="center"&gt;Dur&lt;/td&gt;
      &lt;/th&gt;
      &lt;tr  &gt;
          &lt;p&gt;
          &lt;td&gt;&lt;input type="checkbox" required="required" name="chk[]" checked="checked" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input style="width:100px" type="text" readonly="readonly" name="coa[]" value="&lt;?php echo $co; ?&gt;"&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;select name="Projectname[]" style="font-size:10pt"&gt;
                  &lt;option selected="selected" required="required"&gt;Select project&lt;/option&gt;
                  &lt;?php
                      foreach($proj as $item){
                  ?&gt;
                  &lt;option value="&lt;?php echo $item; ?&gt;"&gt;&lt;?php echo $item; ?&gt;&lt;/option&gt;
                  &lt;?php
                      }                           
                      mysqli_close($conn);
                  ?&gt;
              &lt;/select&gt;   
          &lt;/td&gt;
          &lt;td&gt;&lt;input style="width:100px" type="text" required="required" name="Subproj[]"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input style="width:130px" type="text" required="required" name="Changefrom[]"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input style="width:130px" type="text" required="required" name="Changeto[]"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input style="width:300px" type="text" required="required" name="Activity[]"&gt;&lt;/td&gt;                      
          &lt;td&gt;&lt;input style="width:90px" type="text" required="required" name="Resp[]"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" required="required" class="small"  name="Durest[]"&gt;&lt;/td&gt;
          &lt;/p&gt;
      &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>PHP script:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
      include("../../db_conn_ci_i.php");
      if(isset($_POST)==true &amp;&amp; empty($_POST)==false){
      $co=$_POST['co'];               
      $chkbox = $_POST['chk'];
      $Projectname=$_POST['Projectname'];
      $Subproj=$_POST['Subproj'];         
      $Changefrom=$_POST['Changefrom'];
      $Changeto=$_POST['Changeto'];   
      $Activity=$_POST['Activity'];   
      $Resp=$_POST['Resp'];
      $Durest=$_POST['Durest'];
      }
      $pco=implode(',',$co);
      $pa=implode(',',$Projectname);
      $pb=implode(',',$Subproj);
      $c=implode(',',$Changefrom);
      $d=implode(',',$Changeto);
      $e=implode(',',$Activity);
      $f=implode(',',$Resp);
      $g=implode(',',$Durest);
  
      $sql=" INSERT INTO projects (co,Projectname,Subproj,Changefrom,Changeto,Activity,Resp,Durest) 
      VALUES ('.$pco.','.$pa.','.$pb.','.$c.','.$d.','.$e.','.$f.','.$g.')    ";
      $query = mysqli_query($conn,$sql);
  
  etc,etc
  ?&gt;
  </code></pre>
  
  <p>Any advice?
  Thank you.</p>