Jump to content

Recommended Posts

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'] . '" /> &nbsp; &nbsp;';
    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 administrator
mysql_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 checked
foreach($_POST['banip'] as $ipkey => $ip)
{
    $sql = "DELETE FROM banned_ip (`banned_ip`) VALUES ('$ip')";
    mysql_query($sql);
}
// if successful we do this
echo "<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?
Link to comment
https://forums.phpfreaks.com/topic/15752-cant-get-the-data-to-delete-from-db/
Share on other sites

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 this
echo "<center><font face='Verdana' size='2'>IP address $ip has been reinstated.<br />";[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.