Jump to content

Update Help


Mr Chris

Recommended Posts

Update problem using foreach

 

Hi,

 

I have a page where I wish to update two vaues in my database:

 

http://www.slougheaz.org/football/app_test.php?report_id=1&team_id=1

 

Now if I change any of these two values to different names and hit submit (please try it).  The player_two value I select overwrites the first value.  Can anyone see why?  I know there is a foreach problem, but I don't see what

 

Thanks

 

<?php

if(isset($_REQUEST['Submit']))
{

// Values used for all three tables
  $team_id = $_GET['team_id'];
  $lastinsert = '1';
  
// Values to be inserted into reports table 
foreach($_REQUEST['r'] as $row) 
{ 
  $player_id = $_POST['player_id'];
}

// IF i'm not getting data then insert into various tables
if(isset($_GET['report_id']))
{
{
foreach($_REQUEST['r'] as $row) 
   { 
  mysql_query("Update `stats` set player_id='".$row['player_id']."', team_id='$team_id', report_id='".$lastinsert."' where report_id = '1'");
   }
}

} //End of POST submit
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Player Stats</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="stats" method="post" action="">
  <table width="100%" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td width="14%">Player One/:</td>
      <td width="86%">
      <select class="input" name="r[1]player_id" size="1"  style="width: 145" tabindex="1">
                      <option value="" selected>Goalkeeper</option>
                      <?php 

          $type_array=get_player_names(); 

          foreach ($type_array as $players) 

          { 

          print("<option value=\"".$players['player_id']."\">".$players['player_name']."</option>\n"); 

          } 

        ?>
                    </select>
        </td>
    </tr>
    <tr>
      <td>Player Two:</td>
      <td>
      <select class="input" name="r[2]player_id" size="1"  style="width: 145" tabindex="1">
                      <option value="" selected>Goalkeeper</option>
                      <?php 

          $type_array=get_player_names(); 

          foreach ($type_array as $players) 

          { 

          print("<option value=\"".$players['player_id']."\">".$players['player_name']."</option>\n"); 

          } 

        ?>
                    </select>
        </span>
    </tr>
  </table>
  <input type="submit" name="Submit" value="Submit" class="button">
  <input type="reset" name="Reset" value="Reset" class="button">
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/56832-update-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.