title: add values from dynamically added rows into database
body: <p>hi i am working on a php form which has to add a table row dynamically when add button is pressed and i am using for loop to save the values  the problem is that it is not saving the data into my database and gives the error that the loop values of my textbox is undefined 
  can anyone help me
  here is my script</p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  var i=1;
  function addRow()
  {
            var tbl = document.getElementById('table1');
            var lastRow = tbl.rows.length;
            var iteration = lastRow - 1;
            var row = tbl.insertRow(lastRow);
  
            var firstCell = row.insertCell(0);
            var el = document.createElement('input');
            el.type = 'text';
            el.name = 'name' + i;
            el.id = 'name' + i;
            el.size = 20;
            el.maxlength = 20;
            firstCell.appendChild(el);
  
            var secondCell = row.insertCell(1);
            var el2 = document.createElement('input');
            el2.type = 'text';
            el2.name = 'address' + i;
            el2.id = 'address' + i;
            el2.size = 20;
            el2.maxlength = 20;
            secondCell.appendChild(el2);
  
            var thirdCell = row.insertCell(2);
            var el3 = document.createElement('input');
            el3.type = 'text';
            el3.name = 'contactNum' + i;
            el3.id = 'contactNum' + i;
            el3.size = 20;
            el3.maxlength = 20;
            thirdCell.appendChild(el3);
            alert(i);
            i++;
            frm.h.value=i;
            alert(i);
  
  }
  &lt;/script&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;&lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="submit.php" method="post" name="frm" id="frm"&gt;
  &lt;table width="40%" border="2" cellpadding="0" cellspacing="0" id="table1"&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Address&lt;/strong&gt; &lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Contact Num&lt;/strong&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input name="name" type="text" id="name" size="20" maxlength="20" /&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input name="address" type="text" id="address" size="20" maxlength="20" /&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input name="contactNum" type="text" id="contactNum" size="20" maxlength="12" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;input type="button" value="Add" onclick="addRow();" /&gt;
  &lt;input name="Submit" type="submit" value="Submit" /&gt;
  &lt;label&gt;
  &lt;input name="h" type="hidden" id="h" value="0" /&gt;
  &lt;/label&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>hereis my submit.php code</p>
  
  <pre><code>&lt;?php
  mysql_connect("localhost", "root", '')or die(mysql_error());
  mysql_select_db("test") or die(mysql_error());
  $num =  $_POST['h'];
  for($i=0;$i&lt;=$num;$i++)
  {
  
          $name       = $_POST["name_$i"];
          $address    = $_POST["address_$i"];
          $contactNum = $_POST["contactNum_$i"];
  
  mysql_query("INSERT INTO `com`(`name`, `add`, contact) Values('$name', '$address', '$contactNum')") or die(mysql_error());
  }
  echo "&lt;h1&gt;Done!&lt;/h1&gt;";
  
  ?&gt;
  </code></pre>