Malevolence Posted January 3, 2008 Share Posted January 3, 2008 Hey Again, I have a password protected CPanel with a Ban/Unban IP page. This page shows a table of the Banned IP's and The reason. It also has an 'unban' button next to it. That links to a file called 'ubs.php' and then 'ubs.php' uses $_GET to grab the IP Address and DELETE that row of data from the database WHERE IP = the variable containing the IP from the URL. For some reason it doesn't work. Perhaps I could do this without redirecting them to another page???? Even so, with a page? Heres the some of the code: ban/unban page echo " <h1>Ban/Unban IP Addresses from Access to the entire Site</h1> <p>List of Banned IP's <table width='588' height='51' border='1' cellpadding='8' cellspacing='0'> <tr> <th width='174'>Banned IP Address</th> <th width='289'>Reason for Ban</th> <th width='69'>Unban?</th> </tr>"; mysql_select_db("runescapez_bans") or die(mysql_error()); $listget = mysql_query("SELECT * FROM bannedips ORDER BY IP ASC"); while($row = mysql_fetch_array($listget)) { echo "<td>" . $row['IP'] . "</td>"; echo "<td>" . $row['Reason'] . "</td>"; echo "<td>" . "<a href='ubs.php?ip=" . $row['IP'] . "'>Unban</a>" . "</td>"; echo "</tr>"; } echo '</table><br><br>'; if (!isset($_POST['submit'])) { echo ' <h1>Ban IP</h1><br><br> <form action="" method="post"> <font size="2" face="Arial, Helvetica, sans-serif"> IP Address to Ban: <input name="IP" type="text" size="20"> <br> <br> Reason for Ban: <textarea name="Reason" cols="33" rows="5" wrap="VIRTUAL"></textarea> <br> <br> <input type="submit" name="submit" value="Ban IP"> <input name="reset" type="reset" id="reset" value="Clear Form"> </font> </form> '; } else { $IP = $_POST['IP']; $IP = $_POST['Reason']; mysql_query("INSERT INTO `bannedips` (IP, Reason) VALUES ('$IP', '$Reason')"); echo "IP Address Banned Successfully. If you have made an error, please remove the user from the Table Above."; } echo '<br><br>'; echo '<a href=logout.php>Log Out</a>'; ubs.php mysql_select_db("runescapez_bans") or die(mysql_error()); $delip == $_GET["ip"]; mysql_query("DELETE FROM 'bannedips' WHERE 'IP' = '" . $delip . "'"); header("Location: ipbans.php"); I've hidden all the other code as it is irrelevant. Also, the table appears wrong; as the IP address is displayed, then a blank column, then the unban link, then on the NEXT row; the Reason appears with another link to unban.... Coudl you fix this too? Thanks in Advance, Dan. Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/ Share on other sites More sharing options...
roopurt18 Posted January 3, 2008 Share Posted January 3, 2008 You can fix the table by echo()'ing a tr while looping over the rows. Anytime you have an interaction with the database that is failing, slap this onto the statement: or die(mysql_error()); That will kill the script and give you the mysql reason why. After all, it's difficult to debug something if you don't have any information, isn't it? mysql_query("DELETE FROM 'bannedips' WHERE 'IP' = '" . $delip . "'") or die(mysql_error()); I can tell you now though, that the reason it is dying is your single quotes around the table and column name; that is invalid MySQL syntax. You place backticks, which is the un-shifted tilde key, around table and column names. In MySQL, single quotes surround data. Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429486 Share on other sites More sharing options...
Malevolence Posted January 3, 2008 Author Share Posted January 3, 2008 hey, The table still shows up as different rows but the same data. Also, there are no errors returned but it doesn't delete the data. $delip == $_GET["ip"]; mysql_query("DELETE FROM `bannedips` WHERE `IP` =" . "'" . $delip . "'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429504 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Change $delip == $_GET["ip"]; mysql_query("DELETE FROM `bannedips` WHERE `IP` =" . "'" . $delip . "'") or die(mysql_error()); to $delip = $_GET["ip"]; mysql_query("DELETE FROM `bannedips` WHERE `IP` ='$delip'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429508 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 got beat dam $delip =$_GET["ip"]; Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429513 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 If it is not deleting, then chances are the $delip is not containing the ID. Echo out the SQL and see if it looks correct and have the correct data. Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429516 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 And it wouldnt using == Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429517 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 <?php mysql_select_db("runescapez_bans") or die(mysql_error()); if(isset($_GET['ip'])){ $delip=$_GET["ip"]; $d="DELETE FROM bannedips WHERE IP = '$delip' "; $dr=mysql_query($d)or die(mysql_error()); header("Location: ipbans.php"); exit; }else{}; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429519 Share on other sites More sharing options...
Malevolence Posted January 3, 2008 Author Share Posted January 3, 2008 Thanks you guys; And oops about the == mistake :S. It all works; my mistake with the table was that it posts both the IP and Reason to the IP field in the Database rather than posting IP to IP and Reason to Reason. :S. Now for a little IP Block test..... :S Quote Link to comment https://forums.phpfreaks.com/topic/84329-solved-how-to-delete-from-mysql-table-based-on-what-the-user-clicks/#findComment-429531 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.