title: Undefined offset notice with array within foreach loop
body: <p>i have a form.php with an array posting to update.php to update a mysql db.
  The relevant parts of each are:</p>
  
  <p>form.php</p>
  
  <pre><code> if ($type == "1")      {echo ' 
      &lt;input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/&gt;
      &lt;input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/&gt;
  
      &lt;input  type="text"  name="serialnum[]" value="'. $row['SerialNumber'] .'"/&gt;
      &lt;input type="text"  name="unitsize[]" value="'. $row['UnitSize'] .'"/&gt;
      &lt;input type="text"  name="prop1[]" value="'. $row['Prop1'] .'"/&gt;    
      &lt;input  type="text"  name="latitude[]" value="'. $row['Latitude'] .'"/&gt;
      &lt;input  type="text"  name="longitude[]" value="'. $row['Longitude'] .'"/&gt;
                  ';}  
  if ($type == "2")       {echo ' 
      &lt;input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/&gt;
      &lt;input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/&gt;
  
      &lt;input type="text"  name="serialnum[]" value="'. $row['SerialNumber'] .'"/&gt;
      &lt;input type="text"  name="unitsize[]" value="'. $row['UnitSize'] .'"/&gt;
      &lt;input type="text"  name="prop2[]"  value="'. $row['Prop2'] .'"/&gt;
      &lt;input type="text"  name="latitude[]" value="'. $row['Latitude'] .'"/&gt;
      &lt;input type="text"  name="longitude[]" value="'. $row['Longitude'] .'"/&gt;
                  ';}     
  </code></pre>
  
  <p>Update.php</p>
  
  <pre><code>foreach ($_POST['aid'] as $key=&gt;$assetid) {
  $atype = $_POST['atype'][$key];
  if ($atype == "1")      {   
  
      $stmt =  $mysqli-&gt;stmt_init();
      $query = "UPDATE asset SET 
               SerialNumber=?,UnitSize=?,Prop1=?,Latitude=?,Longitude=?  WHERE AID = ?";
      if($stmt-&gt;prepare($query)) {
  
      $stmt-&gt;bind_param('sdddds', $serialnum, $unitsize, $prop1, $lat, $long, $assetid);
  
          $assetid = $_POST['aid'][$key];
          $serialnum = $_POST['serialnum'][$key];
          $unitsize = $_POST['unitsize'][$key];
          $prop1 = $_POST['prop1'][$key];
          $lat = $_POST['latitude'][$key];
          $long = $_POST['longitude'][$key];
          $stmt-&gt;execute();
      $stmt-&gt;close();
      }
  }
  elseif ($atype == "2")      {   
  
      $stmt =  $mysqli-&gt;stmt_init();
      $query = "UPDATE asset SET 
               SerialNumber=?,Prop2=?, Latitude=?,Longitude=? WHERE AID = ?";
      if($stmt-&gt;prepare($query)) {
  
      $stmt-&gt;bind_param('ssdds', $serialnum, $prop2, $lat, $long, $assetid);
  
          $assetid = $_POST['aid'][$key];
          $serialnum = $_POST['serialnum'][$key];
          $prop2 = $_POST['prop2'][$key];
          $lat = $_POST['latitude'][$key];
          $long = $_POST['longitude'][$key];
          $stmt-&gt;execute();
      $stmt-&gt;close();
       }
  }}
  </code></pre>
  
  <p>This works great for all but one of the inputs in the array.
  I keep getting the following:</p>
  
  <blockquote>
    <p>Notice: Undefined offset: 3</p>
  </blockquote>
  
  <p>relating to the following line:</p>
  
  <pre><code>$prop2 = $_POST['prop2'][$key];
  </code></pre>
  
  <p>All the other DB fields are updating fine except for this one. Can anyone point me in the right direction please?</p>