View Full Version : Updating values in a db

07-01-2007, 08:40 PM
Hi All,

Wondering if someone could help me with my last part of my update script which records players an goalscorers in a five-aside football match Here's my database:


and I want to do two things:

1) Output the values into my form (code posted below) where match_id=1 (via get)
2) Update these values upon submit

Now, i've tried to do this below, but got very stuck writing this update script.

Can anyone please help?



$match_id = $_GET['match_id'];
foreach($_REQUEST['r'] as $position => $row)
$x = implode("', '",$row);
$position = $x[0];
$name = $x[1];
$result = mysql_query("UPDATE player_stats SET position='$position',name='$name', goals='$goals', match_id='$match_id' WHERE match_id=".$_GET['match_id']);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Player stats</title>

<form name="statistics" method="post" action="">
<table width="100%">
$result = mysql_query("SELECT * FROM player_stats WHERE match_id=".$_GET['match_id']);

$numresults = mysql_num_rows($result);

for ($i = 0; $i < $numresults; $i++)
$player = mysql_fetch_array($result);

$name = $row['name'];
$goals = $row['goals'];
$match_id = $row['match_id'];

<td width="33%">Player</td>
<td width="33%">Name</td>
<td width="33%">Goals</td>
<td width="33%">Goalkeeper:</td>
<td width="33%"><input name="r[goalkeeper][name]" type="text" value="'. $row['name'] .'" size="36" /></td>
<td width="33%"><input name="r[goalkeeper][goals]" type="text" value="'. $row['goals'] .'" size="36" /></td>
<td width="33%">Player Two</td>
<td width="33%"><input name="r[player_two][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_two][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
<td width="33%">Player Three</td>
<td width="33%"><input name="r[player_three][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_three][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
<td width="33%">Player Four</td>
<td width="33%"><input name="r[player_four][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_four][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
<td width="33%">Player Five</td>
<td width="33%"><input name="r[player_five][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_five][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
<input type="submit" name="Submit" value="Submit"/>

07-01-2007, 09:56 PM
You should be using die on your query to see if it errors out.

$result = mysql_query("UPDATE player_stats SET position='$position',name='$name', goals='$goals', match_id='$match_id' WHERE match_id=".$_GET['match_id']) or die(mysql_error());
Do you get any errors from that?

07-01-2007, 11:17 PM

But No I get no errors - it just outputs five lots of my form!!:


Whereas I just simply want to echo the information out of the database:


and place each piece of information back in the form, from where I can then update by pressing submit.

Any ideas?

Many Thanks


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum