netman182 Posted January 5, 2010 Share Posted January 5, 2010 i am trying to update multiple rows. i have no issue displying the information i want to update but when i press submit no records get updated. could i get some help? am i missing something? thanks <?php include 'dbc.php'; $tbl_name="players"; // Table name // Connect to server and select databse. $sql="select * from players where teamid='$_POST[teamid]'"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Last name</strong></td> <td align="center"><strong>Team ID</strong></td> <td align="center"><strong>Games Played</strong></td> <td align="center"><strong>Goals</strong></td> <td align="center"><strong>Assists</strong></td> <td align="center"><strong>Points</strong></td> <td align="center" bgcolor="#FFFF00"><strong>Yellow Cards</strong></td> <td align="center" bgcolor="#FF0000"><strong>Red Cards</strong></td> <td align="center"><strong>Suspension</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $id[]=$rows['ID']; ?><? echo $rows['ID']; ?></td> <td align="center"><input name="first[]" type="text" id="first" size="15" value="<? echo $rows['first']; ?>" disabled="disabled"></td> <td align="center"><input name="last[]" type="text" id="last" size="15" value="<? echo $rows['last']; ?>" disabled="disabled"></td> <td align="center"><input name="teamid[]" type="text" id="teamid" size="15" value="<? echo $rows['teamid']; ?>" disabled="disabled"></td> <td align="center"><input name="gp[]" type="text" id="gp" size="10" value="<? echo $rows['gp']; ?>"></td> <td align="center"><input name="goal[]" type="text" id="goal" size="10" value="<? echo $rows['goal']; ?>"></td> <td align="center"><input name="assist[]" type="text" id="assist" size="10" value="<? echo $rows['assist']; ?>"></td> <td align="center"><input name="point[]" type="text" id="point" size="10" value="<? echo $rows['point']; ?>"></td> <td align="center"><input name="yellow[]" type="text" id="yellow" size="10" value="<? echo $rows['yellow']; ?>"></td> <td align="center"><input name="red[]" type="text" id="red" size="10" value="<? echo $rows['red']; ?>"></td> <td align="center"><input name="susp[]" type="text" id="susp" size="10" value="<? echo $rows['susp']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE players SET gp='$gp[$i]', goal='$goal[$i]', assist='$assist[$i]', point='$point[$i]', yellow='$yellow[$i]', red='$red[$i]', susp='$susp[$i]' WHERE ID='$ID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/187209-updating-multiple-rows/ Share on other sites More sharing options...
monkeypaw201 Posted January 5, 2010 Share Posted January 5, 2010 Might I suggest to stat by using the ` around all mysql fields and trying again. Often times that solves it for me. $sql1="UPDATE `players` SET `gp`='$gp[$i]', `goal`='$goal[$i]', `assist`='$assist[$i]', `point`='$point[$i]', `yellow`='$yellow[$i]', `red`='$red[$i]', `susp`='$susp[$i]' WHERE `ID`='$ID[$i]'"; Link to comment https://forums.phpfreaks.com/topic/187209-updating-multiple-rows/#findComment-988615 Share on other sites More sharing options...
Tazerenix Posted January 5, 2010 Share Posted January 5, 2010 may i just add in your table is: <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Last name</strong></td> <td align="center"><strong>Team ID</strong></td> <td align="center"><strong>Games Played</strong></td> <td align="center"><strong>Goals</strong></td> <td align="center"><strong>Assists</strong></td> <td align="center"><strong>Points</strong></td> <td align="center" bgcolor="#FFFF00"><strong>Yellow Cards</strong></td> <td align="center" bgcolor="#FF0000"><strong>Red Cards</strong></td> <td align="center"><strong>Suspension</strong></td> </tr> meant to be the header of the rows because the tag for row headers is <th> and it automatically makes the text in it bold. Just though i'd let you know Link to comment https://forums.phpfreaks.com/topic/187209-updating-multiple-rows/#findComment-988617 Share on other sites More sharing options...
netman182 Posted January 5, 2010 Author Share Posted January 5, 2010 so far that hasn't solved my problem. i thought of doing that also. any other ideas? Link to comment https://forums.phpfreaks.com/topic/187209-updating-multiple-rows/#findComment-988654 Share on other sites More sharing options...
netman182 Posted January 7, 2010 Author Share Posted January 7, 2010 i am still having problems with the sql statement. can someone help me out? Link to comment https://forums.phpfreaks.com/topic/187209-updating-multiple-rows/#findComment-990149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.