Mr Chris Posted June 27, 2007 Share Posted June 27, 2007 Hi, I'm having some problems updating values in my database and am looking for help please, as i'm struggling with it: Here's my database with data in it called player_statistics My first problem: (1) When I try and call the data out of my database for match_id=1 (using GET) back into my form it duplicates the the first entry in every form element like so: Here's my second problem: (2) When I try to edit all data and fill in all the boxes with all different data - (ie Update) and hit submit, my data is then saved strangely like this in the MYSQL database like so: Would anyone be able to help? <?php if(isset($_GET['match_id'])) { $result = mysql_query("Select * From player_stats where match_id=".$_GET['match_id']); $row = mysql_fetch_array($result); $name = $row['name']; $goals = $row['goals']; $match_id = $row['match_id']; } if(isset($_POST['Submit'])) { 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Player stats</title> </head> <body> <form name="statistics" method="post" action=""> <table width="100%"> <tr> <td width="33%">Player</td> <td width="33%">Name</td> <td width="33%">Goals</td> </tr> <tr> <td width="33%">Goalkeeper:</td> <td width="33%"><input name="r[goalkeeper][name]" type="text" value="<?php echo $name?>" size="36" /></td> <td width="33%"><input name="r[goalkeeper][goals]" type="text" value="<?php echo $goals?>" size="36" /></td> </tr> <tr> <td width="33%">Player Two</td> <td width="33%"><input name="r[player_two][name]" type="text" value="<?php echo $name?>" size="36" /></td> <td width="33%"><input name="r[player_two][goals]" type="text" value="<?php echo $goals?>" size="36" /></td> </tr> <tr> <td width="33%">Player Three</td> <td width="33%"><input name="r[player_three][name]" type="text" value="<?php echo $name?>" size="36" /></td> <td width="33%"><input name="r[player_three][goals]" type="text" value="<?php echo $goals?>" size="36" /></td> </tr> <tr> <td width="33%">Player Four</td> <td width="33%"><input name="r[player_four][name]" type="text" value="<?php echo $name?>" size="36" /></td> <td width="33%"><input name="r[player_four][goals]" type="text" value="<?php echo $goals?>" size="36" /></td> </tr> <tr> <td width="33%">Player Five</td> <td width="33%"><input name="r[player_five][name]" type="text" value="<?php echo $name?>" size="36" /></td> <td width="33%"><input name="r[player_five][goals]" type="text" value="<?php echo $goals?>" size="36" /></td> </tr> </table> <input type="submit" name="Submit" value="Submit"/> </form> </body> </html> Thank you Quote Link to comment Share on other sites More sharing options...
Krunk Posted June 27, 2007 Share Posted June 27, 2007 In the form did you men to leave the action attribute as "". Because as is it's not submitting to your process form. But it is strange that it is putting values in your table. <form name="statistics" method="post" action=""> needs to be <form name="statistics" method="post" action="yourprocesscript.php"> I'm having similar dificulty with my form even appearing. (see my post on this page) Quote Link to comment Share on other sites More sharing options...
Krunk Posted June 27, 2007 Share Posted June 27, 2007 Also I think this is wrong: <?php echo $goals?> You need the quotes <?php echo "$goals" ?> in every case The way it is, the question mark becomes part of the $goal variable so that php sees $goal is read as $goal? I believe the lines in the table should look like this: <td width="33%"><input name="r[player_three][name]" type="text" value="<?php echo "$name" ?>" size="36" /></td> Anyone please correct me if I'm wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.