title: Cant validate dynamic form with php
body: <p>I have a problem with validating my dynamic html form using my php script. When I push submit, it says that there is undefined index, but this index is defined. My question different from others, because I'm trying to write all this code to the single php file. What's wrong with my code? </p>
  
  <p><strong>My HTML:</strong></p>
  
  <pre><code>&lt;form method="POST" action="/vehicles/add"&gt;  
      &lt;div class="table-responsive"&gt;  
          &lt;table class="table table-bordered" id="dynamic_field"&gt;  
              &lt;tr&gt;  
                  &lt;td&gt;&lt;input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" required&gt;&lt;/td&gt;  
                  &lt;td&gt;&lt;button type="button" name="add" id="add" class="btn btn-success"&gt;Add More&lt;/button&gt;&lt;/td&gt;  
              &lt;/tr&gt;  
          &lt;/table&gt;  
      &lt;/div&gt;  
      &lt;input type="submit" name="submit" class="btn btn-primary" value="Submit" /&gt;  
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>My jquery script:</strong></p>
  
  <pre><code>$(document).ready(function(){  
        var i=1;  
        $('#add').click(function(){  
             i++;  
             $('#dynamic_field').append('&lt;tr id="row'+i+'"&gt;&lt;td&gt;&lt;input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /&gt;&lt;/td&gt;&lt;td&gt;&lt;button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove"&gt;X&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;');  
        });  
        $(document).on('click', '.btn_remove', function(){  
             var button_id = $(this).attr("id");   
             $('#row'+button_id+'').remove();  
        });  
        });
  </code></pre>
  
  <p><strong>My PHP script:</strong></p>
  
  <pre><code>if (isset($_POST['name'])) {
      $fields = count($_POST["name"]);
      for($i = 0; $i &lt; $fields; $i++) {
          if(trim($_POST["name"][$i] != ''))  
             {  
                  mysqli_query($CONNECT, "INSERT INTO `vehicles` VALUES('', '$_POST[name][$i]', 0)"); 
             }  
      }
  }
  </code></pre>
  
  <p><strong>My error:</strong></p>
  
  <pre><code>PHP Notice:  Undefined index: submit in
  </code></pre>