Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    Updating values in a db

    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?

    Thanks
    PHP Code:
    <?php 

    if(isset($_POST['Submit'])) 

    $match_id $_GET['match_id']; 
    if(isset(
    $_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"> 
    <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%"> 
    <? 
    $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']; 

    echo
    '<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="'
    $row['name'] .'" size="36" /></td> 
    <td width="33%"><input name="r[goalkeeper][goals]" type="text" value="'
    $row['goals'] .'" size="36" /></td> 
    </tr> 
    <tr> 
    <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> 
    </tr> 
    <tr> 
    <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> 
    </tr> 
    <tr> 
    <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> 
    </tr> 
    <tr> 
    <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> 
    </tr>'


    ?> 
    </table> 
    <input type="submit" name="Submit" value="Submit"/> 
    </form> 
    </body> 
    </html>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You should be using die on your query to see if it errors out.
    PHP Code:
    $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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts
    Thanks,

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

    http://www.slougheaz.org/football/up...php?match_id=1

    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

    Chris
    Last edited by stfc_boy; 07-01-2007 at 10:20 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •