Hi,
I have a script that I want to both insert data in a databse and update it with each dropdown saved as a row in a table.
http://www.slougheaz.org/football/app_test.php?team_id=1
<?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
$player_id = $_POST['player_id'];
// IF i'm not getting data then insert into various tables
if(!isset($_GET['report_id']))
{
// Values to be inserted into goals table
foreach($_REQUEST['r'] as $row)
{
mysql_query("INSERT INTO `stats` ( `player_id`,`team_id`, `report_id` ) VALUES ('".$row['player_id']."', '".(int)$_GET['team_id']."', '".$lastinsert."')") OR DIE(mysql_error());
}
}
else
{
foreach($_REQUEST['r'] as $row)
{
$query_one = mysql_query("Update `stats` set player_id='".$row['player_id']."', team_id='$team_id', report_id='".$lastinsert."' where report_id=".$_GET['report_id']);
}
}
} //End of POST submit
if(isset($_GET['report_id']))
{
//GET data from Reports Table
$query_one = mysql_query("Select * From goals where report_id=".$_GET['report_id']);
$report_id = $row['report_id'];
$player_id = $row['player_id'];
$team_id = $row['team_id'];
}
?>
<!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%">
<?php $p_id = $player_id ? $player_id : ''; ?>
<select class="input" name="r[1]player_id " size="1" style="width: 145" tabindex="1">
<option value="" <?php echo ($p_id == '' ? 'selected="selected"' : ''); ?>>Player One</option>
<?php
$type_array=get_player_names();
foreach ($type_array as $players)
{
print("<option value=\"".$players['player_id']."\""
. ($p_id == $players['player_id'] ? 'selected="selected"' : '')
. ">".$players['player_name']."</option>\n");
}
?>
</select>
</td>
</tr>
<tr>
<td>Player Two:</td>
<td>
<?php $p_id = $player_id ? $player_id : ''; ?>
<select class="input" name="r[2]player_id" size="1" style="width: 145" tabindex="1">
<option value="" <?php echo ($p_id == '' ? 'selected="selected"' : ''); ?>>Player Two</option>
<?php
$type_array=get_player_names();
foreach ($type_array as $players)
{
print("<option value=\"".$players['player_id']."\""
. ($p_id == $players['player_id'] ? 'selected="selected"' : '')
. ">".$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>
Now, say I run an INSERT query by selecting values in the two dropdowns and hitting submit the data is saved in the database lovely:

But say I want to edit this data for report_id=1 I go to my new URL with the values report_id=1:
http://www.slougheaz.org/football/app_test.php?team_id=1&report_id=1
and change the values in the dropdown with two new and different players (ie UPDATING them)
Now all the records in the database are updated that have that report_id - BUT only with the data I select for the second dropdown menu r[2]player_id (ie the same information is updating for each row in the database) despite me selecting different players with different values.
Is there something wrong with my UPDATE statement that is causing this?
Thanks