Greysoul Posted February 28, 2010 Share Posted February 28, 2010 had this working at some point with only one being deleted at a time, but through experiment i lost even that ability. this was my starter code. i'm posting my entire second page in case there's something interfering, but the delete info is near the bottom. i'm sure there's a quick fix, any ideas? as is, it deletes all rows even if none are checked. first page <? // Connect database. $host="localhost"; // Host name. $db_user="greysoul_gs"; // MySQL username. $db_password="test"; // MySQL password. $database="greysoul_leaguedb"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); if (isset($_GET['clan'])) { $clanurl= $_GET['clan']; } // Select all data records in table "name_list" and put them into $result. $result=mysql_query("select * from Players WHERE ClanName='$clanurl' ORDER BY Player"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>::Edit Clan and Player Info</title> </head> <body> <form id="form1" name="form1" method="post" action="clanplayerupdate.php"> <table border="1" cellpadding="3" cellspacing="0"> <tr> <td align="center" bgcolor="#FFCC00"><strong>Delete</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Clan</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Name</strong></td> <td align="center" bgcolor="#FFCC00"><strong>GP</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Scores</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Kills</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Deaths</strong></td> <td align="center" bgcolor="#FFCC00"><strong>SPG</strong></td> <td align="center" bgcolor="#FFCC00"><strong>KPG</strong></td> <td align="center" bgcolor="#FFCC00"><strong>K/D</strong></td> <td align="center" bgcolor="#FFCC00"><strong>FA</strong></td> <td align="center" bgcolor="#FFCC00"><strong>FC</strong></td> <td align="center" bgcolor="#FFCC00"><strong>FP%</strong></td> <td align="center" bgcolor="#FFCC00"><strong>MVP</strong></td> </tr> <? // Fetch record rows in $result by while loop and put them into $row. $x = 0; while($row=mysql_fetch_assoc($result)){ ?> <tr> <td align="center" bgcolor="#FFCC00"><strong><input type="checkbox" name="delete" id="<?=$row[iD]?>" value="<?=$row[iD]?>"></strong></td> <td bgcolor="#FFFFCC"><input name="<? echo 'clanName'.$x; ?>" size="4" type="text" id="<? echo $row['ClanName']; ?>" value="<? echo $row['ClanName']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'playerName'.$x; ?>" size="15" type="text" id="<? echo $row['Player']; ?>" value="<? echo $row['Player']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'gp'.$x; ?>" size="4" type="text" id="<? echo $row['GP']; ?>" value="<? echo $row['GP']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'scores'.$x; ?>" size="4" type="text" id="<? echo $row['Scores']; ?>" value="<? echo $row['Scores']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'kills'.$x; ?>" size="4" type="text" id="<? echo $row['Kills']; ?>" value="<? echo $row['Kills']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'deaths'.$x; ?>" size="4" type="text" id="<? echo $row['Deaths']; ?>" value="<? echo $row['Deaths']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'spg'.$x; ?>" size="4" type="text" id="<? echo $row['SPG']; ?>" value="<? echo $row['SPG']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'kpg'.$x; ?>" size="4" type="text" id="<? echo $row['KPG']; ?>" value="<? echo $row['KPG']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'kd'.$x; ?>" size="4" type="text" id="<? echo $row['KD']; ?>" value="<? echo $row['KD']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'fa'.$x; ?>" size="4" type="text" id="<? echo $row['FA']; ?>" value="<? echo $row['FA']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'fc'.$x; ?>" size="4" type="text" id="<? echo $row['FC']; ?>" value="<? echo $row['FC']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'fp'.$x; ?>" size="4" type="text" id="<? echo $row['FP']; ?>" value="<? echo $row['FP']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="<? echo 'mvp'.$x; ?>" size="4" type="text" id="<? echo $row['MVP']; ?>" value="<? echo $row['MVP']; ?>" /></td> <input type = "hidden" name = "<? echo 'id'.$x ?>" value = "<?echo $row[iD] ?>" /> </tr> <? $x++; } ?> <input type = "hidden" name = "size" value = "<?echo $x; ?>" /> </table> <input type="submit" name="Submit" value="Update" /> <input type="submit" name="delete" id="delete" value="Delete" /> </form> <?php $links=mysql_query("select * from Clans"); while($rows = mysql_fetch_array($links)) { echo '<a href="clanplayeredit.php?clan=' . $rows['ClanName'] . '">' . $rows['ClanName'] . '</a>' . " "; } ?> <br><br><br> <form onsubmit="return validate_form(this)" method="post" action="clanplayerupdate.php"> Player Name: <input type="text" name="Player0" size="20" /> Clan Tag: <input type="text" name="ClanName0" size="20" /> <br> Player Name: <input type="text" name="Player1" size="20" /> Clan Tag: <input type="text" name="ClanName1" size="20" /> <br> <input type="submit" value="Add" /> </form> </body> </html> second page <html> <body> <head> </head> <?php if($_POST['Submit']){ // If receive Submit button variable. // Connect database. $host="localhost"; // Host name. $db_user="greysoul_gs"; // MySQL username. $db_password="test"; // MySQL password. $database="greysoul_leaguedb"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("select Player from Players order by id asc"); $y = 0; while($y < $_POST[size]) { $player=$_POST["playerName".$y]; $clan = $_POST["clanName".$y]; $gp= $_POST["gp".$y]; $scores = $_POST["scores".$y]; $kills = $_POST["kills".$y]; $deaths = $_POST["deaths".$y]; $spg = $_POST["spg".$y]; $kpg = $_POST["kpg".$y]; $kd = $_POST["kd".$y]; $fa = $_POST["fa".$y]; $fc = $_POST["fc".$y]; $fp = $_POST["fp".$y]; $mvp = $_POST["mvp".$y]; $id = $_POST["id".$y]; mysql_query("UPDATE Players SET Player='$player', ClanName = '$clan', GP = '$gp', Scores = '$scores', Kills = '$kills', Deaths = '$deaths', SPG = '$spg', KPG = '$kpg', KD = '$kd', FA = '$fa', FC = '$fc', FP = '$fp', MVP = '$mvp' WHERE ID='$id'"); $y++; } echo "--- Update Complete ---" . "<br>" . "<br>"; } ?> <?php // DELETING CHECK BOXES $host="localhost"; // Host name. $db_user="greysoul_gs"; // MySQL username. $db_password="test"; // MySQL password. $database="greysoul_leaguedb"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); if($_POST['delete']) { foreach($_POST as $playerdel) { // This will loop through the checked checkboxes mysql_query("DELETE FROM Players WHERE ID='$playerdel'"); // This deletes the record from the database } } ?> <?php if (isset($HTTP_REFERER)) { echo "<a href='$HTTP_REFERER'>Back</a>"; } else { echo "<a href='javascript:history.back()'>Click to Go Back</a>"; } ?> <br> <br> <?php $host="localhost"; // Host name. $db_user="greysoul_gs"; // MySQL username. $db_password="test"; // MySQL password. $database="greysoul_leaguedb"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $Playeradd= $_POST['Player0']; $ClanNameadd= $_POST['ClanName0']; $Player1add= $_POST['Player1']; $ClanName1add= $_POST['ClanName1']; $insert="INSERT INTO Players (ID, Player, ClanName)VALUES ('NULL','".$Playeradd."', '".$ClanNameadd."'), ('NULL','".$Player1add."', '".$ClanName1add."')"; mysql_query($insert) or die ('Error updating database'); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/193637-check-boxes-deleting-several-rows/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.