title: php submit only giving last value from array that populates form
body: <p>Struggling with a one page form that i want to first populate a form from a mysql query, then enable a user to update some of the values in each of several table rows from text input fields in the form.  </p>
  
  <p>The code's intent is to update the field by referencing the row ID.</p>
  
  <p>But for some reason I'm only able to update the last row in the form (the last row from the array).  I've included some troubleshooting code to see what the ID variable is and it always comes up as the last iteration of the array.  I think I'm either overwriting the ID variable in the while loop or the for loop.</p>
  
  <p>I have tried moving the POST/update to a 2nd file but get the same results.  Any thoughts/suggestions would be greatly appreciated</p>
  
  <p>Here is the code minus the db connection:</p>
  
  <pre><code>$saveClicked = $_POST["saveClicked"];
  
  
  {   //  SAVE button was clicked 
      if (isset($saveClicked)) {
          unset($saveClicked);
  
  
          $ID = $_POST["ID"]; 
  
          $win = $_POST["Winner"];
          $winScr = $_POST["WinnerScore"];
          $losScr = $_POST["LoserScore"];         
  
  
          $tschedule_SQLupdate = "UPDATE tschedule SET ";
  
          $tschedule_SQLupdate .=  "Winner = '".$win."', ";
          $tschedule_SQLupdate .=  "WinnerScore = '".$winScr."', ";
          $tschedule_SQLupdate .=  "LoserScore = '".$losScr."' ";
          $tschedule_SQLupdate .=  "WHERE ID = '".$ID."' ";   
  
  
          if (mysql_query($tschedule_SQLupdate))  {   
  
          echo '&lt;p&gt; the number of mysql affected rows is '.mysql_affected_rows().'&lt;/p&gt;';
          echo 'this is the value for post id '.$ID;
  
          } else {
              echo '&lt;span style="color:red; "&gt;FAILED to update the game.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;';
              echo mysql_error();
  
          }               
      }   
  //  END:  SAVE button was clicked   ie. if (isset($saveClicked))
  }
  
  
  {   //  Get the details of all associated schedule records
      //      and store in array:  gameArray  with key &gt;$indx  
  
          $indx = 0;
  
          $tschedule_SQLselect = "SELECT * ";
          $tschedule_SQLselect .= "FROM ";
          $tschedule_SQLselect .= "tschedule ";
          $tschedule_SQLselect .= "WHERE week = 1 ";
  
          $tschedule_SQLselect_Query = mysql_query($tschedule_SQLselect); 
  
          while ($row = mysql_fetch_array($tschedule_SQLselect_Query, MYSQL_ASSOC)) {
  
              $gameArray[$indx]['ID'] = $row['ID'];
              $gameArray[$indx]['Date'] = $row['Date'];
              $gameArray[$indx]['week'] = $row['week'];
              $gameArray[$indx]['Favorite'] = $row['Favorite'];               
              $gameArray[$indx]['Line'] = $row['Line'];
              $gameArray[$indx]['Underdog'] = $row['Underdog'];
              $gameArray[$indx]['OU'] = $row['OU'];
              $gameArray[$indx]['Winner'] = $row['Winner'];
              $gameArray[$indx]['WinnerScore'] = $row['WinnerScore'];
              $gameArray[$indx]['LoserScore'] = $row['LoserScore'];   
              $indx++;             
          }
  
          $numGames = sizeof($gameArray);
  
          mysql_free_result($tschedule_SQLselect_Query);          
  }
  
  {   //      Output 
  
              echo '&lt;form name ="postGame" action="'.$thisScriptName.'" method="post"&gt;';      
  
                  echo '&lt;table border="1"&gt;';
                      echo '&lt;tr&gt;
                                 &lt;th&gt;ID&lt;/th&gt;
                                  &lt;th class="date"&gt;Date&lt;/th&gt;
                                  &lt;th class="num"&gt;Week&lt;/th&gt;
                                  &lt;th&gt;Favorite&lt;/th&gt;
                                  &lt;th class="num"&gt;Line&lt;/th&gt;
                                  &lt;th&gt;Underdog&lt;/th&gt;
                                  &lt;th class="num"&gt;OU&lt;/th&gt;
                                  &lt;th&gt;Winner&lt;/th&gt;
                                  &lt;th&gt;WScore&lt;/th&gt;
                                  &lt;th&gt;LScore&lt;/th&gt;
                                  &lt;th&gt;Save&lt;/th&gt;   
                              &lt;/tr&gt;   ';  
  
      for ($indx = 0; $indx &lt; $numGames; $indx++) {
      $thisID = $gameArray[$indx]['ID'];
      $saveLink = '&lt;input type = "submit" value = "Save" /&gt;';
  
              $fld_ID = '&lt;input type="text" name="ID" value="'.$thisID.'"/&gt;';
  
              $fld_saveClicked = '&lt;input type="hidden" name="saveClicked" value="1"/&gt;';
  
  
              echo $fld_ID;
              echo $fld_saveClicked;
                          echo '&lt;tr&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['ID'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['Date'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['week'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['Favorite'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['Line'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['Underdog'].'&lt;/td&gt;
                                      &lt;td&gt;'.$gameArray[$indx]['OU'].'&lt;/td&gt;
                                      &lt;td&gt;&lt;input type="text" size =5 name="Winner"&gt;'.$gameArray[$indx]['Winner'].'&lt;/td&gt;
                                      &lt;td&gt;&lt;input type="number" size=5 name="WinnerScore"&gt;'.$gameArray[$indx]['WinnerScore'].'&lt;/td&gt;
                                      &lt;td&gt;&lt;input type="number" size=5 name="LoserScore"&gt;'.$gameArray[$indx]['LoserScore'].'&lt;/td&gt;
                                      &lt;td&gt;'.$saveLink.'&lt;/td&gt;
                                  &lt;/tr&gt;   ';      
  
                      }
  
                      echo '&lt;/table&gt;';
  
                  echo '&lt;/form&gt;';
  
  echo' &lt;a href ="../schedules/schedView.php"&gt;View Schedule&lt;/a&gt;';     
  
  }
  </code></pre>