simcoweb Posted July 26, 2006 Share Posted July 26, 2006 I have this code in a script that parses the data from a form and inserts it into the MySQL database.[code]echo '<form action="unban.php" method="POST">';while($row = mysql_fetch_array($result)){ echo "<br><table width='400' border='1' padding='3'><tr><td align='center'>"; echo '<input type="checkbox" name="banip[]" value="' . $row['banned_ip'] . '" /> '; echo $row['banned_ip'] . "<br />\n"; echo "</td></tr></table><br />"; }if (mysql_num_rows($result) == 0){ echo "<p><center>There are currently no banned IP addresses in the database.";}else{echo "<p><center>Here are the current banned IP addresses. Select the checkbox next to any IP you wish to unban and click below<br>";echo '<br><input type="submit" name="unban" value="UnBan Selected"></form>'; }[/code]This is the code i'm trying to use to delete the items upon hitting submit IF they are checkmarked:[code]$ip = $_POST['banip'];// this will erase the banned IP addresses chosen by the administratormysql_connect($dbhost, $dbuser, $dbpass) or die('No database connection!');mysql_select_db($dbname) or die('Cannot find that darn database!');// now we run our query and deletion based upon what is checkedforeach($_POST['banip'] as $ipkey => $ip){ $sql = "DELETE FROM banned_ip (`banned_ip`) VALUES ('$ip')"; mysql_query($sql);}// if successful we do thisecho "<center><font face='Verdana' size='2'>IP address $ip has been reinstated.<br />";[/code]The first section of code works just peachy. It displays the IP addresses that i've selected to be banned along with a checkbox next to it. the second section extracts that value and uses it to delete the checkmarked item. It gives me a successful message that the IP address has been reinstated but when I check again the IP address was not deleted. Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/15752-cant-get-the-data-to-delete-from-db/ Share on other sites More sharing options...
trq Posted July 26, 2006 Share Posted July 26, 2006 You need to supply your query a WHERE clause. Something like...[code]$sql = "DELETE FROM banned_ip WHERE ip = '$ip'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15752-cant-get-the-data-to-delete-from-db/#findComment-64394 Share on other sites More sharing options...
simcoweb Posted July 27, 2006 Author Share Posted July 27, 2006 Ok, got it. I modified that line as you laid out but still got no results. That's because I kept that one part ('banned_ip') in there thinking it was necessary. I deleted it and now it works fine. Thanks for the help!Finished code:[code]foreach($_POST['banip'] as $ipkey => $ip){ $sql = "DELETE FROM banned_ip WHERE banned_ip = '$ip'"; mysql_query($sql);}// if successful we do thisecho "<center><font face='Verdana' size='2'>IP address $ip has been reinstated.<br />";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15752-cant-get-the-data-to-delete-from-db/#findComment-64401 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.