title: Php $_POST form with multiple variable inputs in foreach loop
body: <p>I have a form which is creating several text input's in a foreach loop like this:</p>
  
  <pre><code>    &lt;?php $results = $wpdb-&gt;get_results( "SELECT * FROM wp_results WHERE event_id = '$event' AND div_id = '$division'" ); ?&gt;
                &lt;form action="" method="post"&gt;
                  &lt;?php foreach ($results as $entry) { ?&gt;
                    &lt;p&gt;
                      &lt;?php echo $entry_name;?&gt;
                      &lt;input type="hidden" name="entry_id" value="$entry-&gt;user_id"&gt;
                      &lt;input type="text" name="position" value=""&gt;
                      &lt;input type="text" name="points" value=""&gt;             
                    &lt;/p&gt;
            &lt;?php    }?&gt;
        &lt;input type="submit" name="submit" value="Save Changes" class="button"&gt;
      &lt;/form&gt;
  &lt;?php
  if ( isset( $_POST['submit'] ) ){
  
  $entry_id = sanitize_text_field($_POST['entry_id']);
  $position = sanitize_text_field($_POST['position']);
  $points = sanitize_text_field($_POST['points']);
  
  $wpdb-&gt;update('wp_results',
      array(
        'position'   =&gt; $position,
        'points'   =&gt; $points,
      ),
      array(
        'user_id' =&gt; $entry_id,
      )
  );
  
  }
  ?&gt;
  </code></pre>
  
  <p>The result is an html form which looks something like this:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
      &lt;p&gt;Aiden Hopkins
        &lt;input type="hidden" name="entry_id" value="98"&gt;
        &lt;input type="text" name="position" value=""&gt;
        &lt;input type="text" name="points" value=""&gt;
      &lt;/p&gt;
      &lt;p&gt;Asha Sykes
        &lt;input type="hidden" name="entry_id" value="75"&gt;
        &lt;input type="text" name="position" value=""&gt;
        &lt;input type="text" name="points" value=""&gt;
      &lt;/p&gt;
      &lt;p&gt;Ffion Hughes
        &lt;input type="hidden" name="entry_id" value="66"&gt;
        &lt;input type="text" name="position" value=""&gt;
        &lt;input type="text" name="points" value=""&gt;
    &lt;input type="submit" name="submit" value="Save Changes" class="button"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem I have is that when I try and submit the form and write the results for each user to the database, it only enters the details for the last instance of the loop and ignores the others.</p>
  
  <p>I have looked at other answers on here such as <a href="https://stackoverflow.com/questions/18538227/how-to-loop-through-an-array-of-inputs-in-a-form">How to loop through an array of inputs in a form?</a> but when I tried that, I got 'Array' for all the db entries. </p>
  
  <p>I'm sure there is a simple way to do this using foreach or something but I'm just getting muddled up with it and I must confess, array's are not my strong point!</p>