title: PHP form to CSV with multiple entries
body: <p>I am trying to create a simple online form using html and php tooutput to a .csv. I have no problem doing this for a single form but the users of this form will usually have multiple entries at once. To make it easier for them I am using a form of which you can add lines to submit more entries in one submission. Below is the HTML and PHP code.</p>
  
  <p><strong>The issue I am having is the PHP part. I can only get it to ever submit the first entry.</strong></p>
  
  <p>Any ideas? I have a working version of the site/form <a href="http://selectbylocation.com" rel="nofollow"><em>here</em></a>, but again, only the first entry every gets entered into the .csv. Thanks for the help.</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;link rel="stylesheet" href="mdcstyle.css" /&gt;
  &lt;title&gt;Submission form&lt;/title&gt;
  
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  
  &lt;script type='text/javascript'&gt;
  //&lt;![CDATA[
   $(document).ready(function() {
    var currentItem = 0;
    $('#addnew').click(function(){
     currentItem++;
     $('#items').val(currentItem);
  var strToAdd = '&lt;tr&gt;&lt;td&gt;Area:&lt;input class="textfield"  name="area'+currentItem+'" id ="area'+currentItem+'"type="text" /&gt;&lt;/td&gt;&lt;td&gt;Contractor:&lt;input class="textfield"  name="contractor'+currentItem+'" id ="contractor'+currentItem+'"type="text" /&gt;&lt;/td&gt;&lt;/tr&gt;';
     $('#data').append(strToAdd);
  
    });
   });
  
  //]]&gt;
  &lt;/script&gt; 
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;div class="content"&gt;
      &lt;h2&gt;header text&lt;/h2&gt;
      &lt;p&gt;Please complete this form for Udpates. Add a new line if you have more than one project.&lt;/p&gt;
    &lt;form id="myform" name="form1" method="post" action="signup2.php"&gt;  
  &lt;table class="dd" width="100px" id="data"&gt;
    &lt;tr&gt;
  
      &lt;td&gt;Area:&lt;input class="textfield" name="area0" id="area0" type="text" /&gt;&lt;/td&gt;
      &lt;td&gt;Contractor:&lt;input class="textfield"  name="contractor0" id="contractor0" type="text" /&gt;&lt;/td&gt;
  
    &lt;/tr&gt;
  &lt;/table&gt;
        &lt;input class="subbutton" type="submit" name="Submit" value="Submit Form"&gt; 
   &lt;/form&gt;   
  
  
  
  &lt;button id="addnew" name="addnew" value="Add new item"&gt;Add new entry&lt;/button&gt;
  &lt;input type="hidden" id="items" name="items" value="1" /&gt; 
          &lt;br&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>&lt;?php
  
  for( $i = 0; $i &lt;= $count; $i++ )
  {
      date_default_timezone_set('America/New_York'); 
      $today = date("m.d.y");   
      $area0 = $_POST['area'.$i];
  
  //the data
  $data = "$today, $area0, $contractor, $hours, $project, $town, $street\n";
  
  //open the file and choose the mode
  $fh = fopen("users2.csv", "a");
  fwrite($fh, $data);
  
  //close the file
  fclose($fh);
  }
  ?&gt;
  </code></pre>