title: how to save the values from Dynamic textbox to database mysql? -- php, jquery
body: <p>My goal is to have dynamic textbox and save the values placed in them to my database.
  I have here JavaScript that allows me to add dynamic textbox</p>
  
  <pre><code>&lt;SCRIPT type="text/javascript"&gt;
  
  $(document).ready(function(){
      var increment=2;
  
      $("#addButton").click(function(){
          if(increment &gt; 5)
          {
              alert('You can only add 5 Textboxes');
              return false;
          }
          // two methods
          // first memthod...we can write div element
          var maincontent="&lt;label&gt;Textbox #"+increment+" : &lt;/label&gt;&lt;input type='textbox' name='textbox"+increment+"' id='textbox"+increment+"'/&gt;";
          var fun="&lt;div id='TextBoxDiv"+increment+"'&gt;"+maincontent+"&lt;/div&gt;";
          //$("#TextBoxesGroup").append(fun);
  
          //second method 
          // here jquery through create div element
  
          var newTextBoxDiv = $(document.createElement('div')).attr('id', 'TextBoxDiv' +increment);
          newTextBoxDiv.after('').html(maincontent);    
          $(newTextBoxDiv).appendTo("#TextBoxesGroup");
  
          increment++;
      });
      $("#removeButton").click(function () {
          if(increment==1){
              alert("No more textbox to remove");
              return false;
          }   
          increment--;
  
          $("#TextBoxDiv" + increment).remove();
      });
  
      $("#getButtonValue").click(function () {
  
          var msg = '';
          for(i=1; i&lt;increment; i++){
              msg += "\n Textbox #" + i + " : " + $('#textbox' +    i).val();
          }
          alert(msg);
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>this is my form</p>
  
  <pre><code>&lt;div id='TextBoxesGroup'&gt;
      &lt;div id="TextBoxDiv1"&gt;
          &lt;label&gt;Textbox #1 : &lt;/label&gt;&lt;input type='text' id='textbox1' name="txt[]"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Can anybody help me with the php side, on how can I save those to the database? I'm new to php.</p>
  
  <p>I tried doing these</p>
  
  <pre><code>&lt;?php
  $txt = (array) $_POST['txt'];
  
  if($_POST['submit'])
  {
      $add = "INSERT INTO `names` (`first`) values ('$txt')";
      mysql_query($add) or die(mysql_error());
  
      echo "Added!";
  ?&gt;
  </code></pre>
  
  <p>nothing happens. It does not add any. please help
  If anyone can help me and lead me through line upon line, I would very much appreciate. Thank you all!!!</p>