title: How can I store dynamically created form inputs to a database using ajax
body: <p>I have asked a similar question but the answers didn't really help me in solving or think of a solution.</p>
  
  <p>I have my JS script upload a file (using PHP as its callback) then take the data from the upload.php and reformat it using the JS code snippet below to show the user the inputs.</p>
  
  <p>When the data is presented to the user it looks like this as an example:</p>
  
  <pre><code>input type="text" class="r" name="scene" value="1" /&gt;
  &lt;input type="text" class="r" name="int_ext" value="INT" /&gt;
  &lt;input type="text" class="r" name="scene_desc" value="Bedroom" /&gt;
  &lt;input type="text" class="r" name="day_night" value="DAY" /&gt;
  
  &lt;input type="text" class="r" name="scene" value="2" /&gt;
  &lt;input type="text" class="r" name="int_ext" value="EXT" /&gt;
  &lt;input type="text" class="r" name="scene_desc" value="Outside" /&gt;
  &lt;input type="text" class="r" name="day_night" value="DAY" /&gt;
  
  &lt;input type="text" class="r" name="scene" value="3" /&gt;
  &lt;input type="text" class="r" name="int_ext" value="INT" /&gt;
  &lt;input type="text" class="r" name="scene_desc" value="Bedroom" /&gt;
  &lt;input type="text" class="r" name="day_night" value="DAY" /&gt;
  
  &lt;input type="text" class="r" name="scene" value="4" /&gt;
  &lt;input type="text" class="r" name="int_ext" value="EXT" /&gt;
  &lt;input type="text" class="r" name="scene_desc" value="Bedroom" /&gt;
  &lt;input type="text" class="r" name="day_night" value="NIGHT" /&gt;
  
  ...
  </code></pre>
  
  <p>this output can range from 100 to 400 sets of inputs. One set is grouped into 4 inputs.</p>
  
  <p>I'm trying to have each dynamic set fit into a query like this</p>
  
  <pre><code>mysql_query("INSERT INTO (`project_id`, `scene_number`, `int_ext`, `scene_description`, `day_night`) VALUES (10, '{$scene_num}', '{$int_ext}', '{$scene_desc}', '{$day_night}')");
  </code></pre>
  
  <p><em>Before anyone points out, In my code I am filtering and cleaning the inputs before inserting them into the database</em></p>
  
  <p>My problem is I can't be creative enough to insert each scene information into the database like I envision it.</p>
  
  <p>In my PHP code I echo out the line:</p>
  
  <pre><code>if(!$word)
      return NULL;
  
  if(preg_match_all($pattern, $contents, $matches))
  {
      foreach($matches as $match) {
          $list = "&lt;li&gt;&lt;div class='int'&gt;".implode("&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class='int'&gt;", $match)."&lt;/div&gt;&lt;/li&gt;\n";
      }
  }else{
      $list = "No matches found";
  }
  </code></pre>
  
  <p>In my JS code I split out the line and divide it into the 4 inputs:</p>
  
  <pre><code>$int.html(function(i, html) {
      return html.replace(/(\d+)(.+)/,function(str,s1,s2){
          var text = s2.split('.');
          var text2 = text[1].split('-');
          var text3 = text2[1].split(' ');
          return '&lt;input class="r" name="scene" value="'+ s1.replace(/^\s*/, '').replace(/\s*$/, '') +'" /&gt;' +
              '&lt;input class="r" name="int_ext" value="'+ text[0].replace(/^\s*/, '').replace(/\s*$/, '') +'" /&gt;' +
              '&lt;input class="r" name="scene_desc" value="'+ text2[0].replace(/^\s*/, '').replace(/\s*$/, '') +'" /&gt;' +
              '&lt;input class="r" name="day_night" value="'+ text3[1].replace(/^\s*/, '').replace(/\s*$/, '') +'" /&gt;';
      });
  });
  </code></pre>
  
  <p>I'm trying to form an AJAX request to send the values to a PHP page for processing, I'm not sure how to grab the data I need and send it off via AJAX (I know how to perform AJAX request, but in this case I don't know how to grab a dynamic number of inputs to be processed).</p>
  
  <p>Any tips?</p>