stfc_boy
07-12-2007, 09:25 PM
Hi Guys,
I’m creating an update script, but am having one problem updating it, which is causing me a headache.
Here’s my database with five rows:
http://www.sloughtownfc.net/statistics.jpg
But when I try to update each row in the database via my php script below, it saves each record as the last entry entered (ie duplicates them):
Can anyone help?
Thanks
Chris
<?php
// Get the data from the league table
$databaseInfo = mysql_query("SELECT * From player_stats") or die(mysql_error());
// Update the new values in the database
if(isset($_POST['Submit']))
{
for($i = 0; $i < count($_REQUEST['nme']) ; $i++)
{
$result = mysql_query("Update player_stats set name ='".$_REQUEST['nme'][$i]."' WHERE match_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
}
for($i = 0; $i < count($_REQUEST['gls']) ; $i++)
{
$result = mysql_query("Update player_stats set goals ='".$_REQUEST['gls'][$i]."' WHERE match_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
header("Location: ../index.php");
}
} //end of post
?>
<form name="table" method="post" action="">
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td width="39%">Position</td>
<td width="7%">Name</td>
<td width="9%">Goals</td>
</tr>
<?php while ($databaseArray = mysql_fetch_array($databaseInfo)){ ?>
<tr>
<td> <input type="hidden" name="id[]" value="<?php echo $databaseArray['name']; ?>">
<?php echo $databaseArray['position']; ?></td>
<td><input name="nme[]" type="text" id="nme" value="<?php echo $databaseArray['name']?>" size="36" /></td>
<td><input name="gls[]" type="text" id="gls" value="<?php echo $databaseArray['goals']?>" size="36" />
</td>
</tr>
<?php } // end of while loop ?>
</table>
<input type="submit" name="Submit" value="Submit" class="button">
</form>
</body>
</html>
I’m creating an update script, but am having one problem updating it, which is causing me a headache.
Here’s my database with five rows:
http://www.sloughtownfc.net/statistics.jpg
But when I try to update each row in the database via my php script below, it saves each record as the last entry entered (ie duplicates them):
Can anyone help?
Thanks
Chris
<?php
// Get the data from the league table
$databaseInfo = mysql_query("SELECT * From player_stats") or die(mysql_error());
// Update the new values in the database
if(isset($_POST['Submit']))
{
for($i = 0; $i < count($_REQUEST['nme']) ; $i++)
{
$result = mysql_query("Update player_stats set name ='".$_REQUEST['nme'][$i]."' WHERE match_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
}
for($i = 0; $i < count($_REQUEST['gls']) ; $i++)
{
$result = mysql_query("Update player_stats set goals ='".$_REQUEST['gls'][$i]."' WHERE match_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
header("Location: ../index.php");
}
} //end of post
?>
<form name="table" method="post" action="">
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td width="39%">Position</td>
<td width="7%">Name</td>
<td width="9%">Goals</td>
</tr>
<?php while ($databaseArray = mysql_fetch_array($databaseInfo)){ ?>
<tr>
<td> <input type="hidden" name="id[]" value="<?php echo $databaseArray['name']; ?>">
<?php echo $databaseArray['position']; ?></td>
<td><input name="nme[]" type="text" id="nme" value="<?php echo $databaseArray['name']?>" size="36" /></td>
<td><input name="gls[]" type="text" id="gls" value="<?php echo $databaseArray['goals']?>" size="36" />
</td>
</tr>
<?php } // end of while loop ?>
</table>
<input type="submit" name="Submit" value="Submit" class="button">
</form>
</body>
</html>