title: PHP - foreach only updates first row
body: <p>I'm trying to update multiple rows using a form and a foreach loop. I've tried solutions found on stackoverflow, but just can't seem to get it to work. I'm working on page project.php?id=13</p>
  
  <p>My HTML form:    </p>
  
  <pre><code>&lt;form method="post" action="project.php?id=&lt;?php echo $id; ?&gt;"&gt;
  &lt;?php while($row = $shops-&gt;fetch_assoc()) : ?&gt;
  &lt;input type="hidden" name="shop[]" value="&lt;?php echo $row['id']; ?&gt;"&gt;
  &lt;input type="text" name="boxposition[]" class="form-control" value="&lt;?php echo $row['box_position']; ?&gt;" style="width: 50px;"&gt;
  &lt;input type="submit" name="update" value="Update Order" class="btn btn-primary"&gt;
  &lt;?php endwhile; ?&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My PHP code (on the same page) which is executed on if(isset($_POST['update'])) :</p>
  
  <pre><code>$shopid = $_POST['shop'];
  $boxorder = $_POST['boxposition'];
  
  foreach ($shopid as $index =&gt; $value) {
  $query = "UPDATE shops SET box_position = '".$boxorder[$index]."' WHERE id = '".$shopid[$index]."'";
  $update_row = $db-&gt;update($query);
  </code></pre>
  
  <p>Unfortunately, it only updates the first row (lowest id). The very strange thing is that I get the correct values when I echo them using. E.g.:</p>
  
  <pre><code>echo $shopid[$index].'&lt;br&gt;';
  echo $boxorder[$index].'&lt;br&gt;';
  </code></pre>
  
  <p>An example:
  I update the $boxorder for 2 rows:<br>
  Row 1 (for shop 1): new value = 6 (old value was 7)<br>
  Row 2 (for shop 2): new value = 8 (old value was 5)</p>
  
  <p>Using foreach to echo the result, it shows the correct values:<br>
  1 (shop id)<br>
  6 (new boxorder value)<br>
  2 (shop id)<br>
  8 (new boxorder value)</p>
  
  <p>What am I missing? Thanks in advance for helping me out!</p>