| Code: |
| <?php
$dbhost = 'localhost'; $dbuser = 'XXXXXXXXXXX'; $dbpass = 'XXXXXXXXXXX'; $dbname = 'XXXXXXXXXXX'; $connection = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()); $database = mysql_select_db($dbname) or die(mysql_error()); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ban</title> </head> <body> <?php if (isset($_POST['submit'])) { $query = mysql_query("SELECT count(id) FROM fdv_akobook_banned WHERE ip='$_POST[ipaddress]'") or exit (mysql_error()); $result = mysql_result($query, 0); if ($result == 1 && ($_POST['delete']=='true')) { $delete = mysql_query("DELETE FROM fdv_akobook_banned WHERE ip='$_POST[ipaddress]'") or exit (mysql_error()); echo "<p>ip $_POST[ipaddres] is verwijderd</p>\n\n<a href='index.php'>Index</a>"; } elseif ($result == 1) { echo "<p>ip $_POST[ipaddres] is al gebanned</p>\n\n<a href='index.php'>Index</a>"; } elseif ($result<1) { $insert = mysql_query("INSERT INTO fdv_akobook_banned (`id`,`ip`) VALUES ('','$_POST[ipaddress]')") or exit (mysql_error()); echo "<p>ip $_POST[ipaddres] is in de banlist geplaatst</p>\n\n<a href='index.php'>Index</a>"; } else {echo 'error';} } else { if (isset($_GET['ip'])) { ?> <form action="index.php" method="post"> <input name="delete" type="hidden" value="true" /> <table> <tr> <th colspan="2">ARE U SURE U WANT TO DELETE THAT IP?</th> </tr> <tr> <td>IP</td><td><input name="ipaddress" type="text" size="20" maxlength="15" value="<?php echo $_GET['ip'];?>" readonly="true" /></td> </tr> <tr> <td colspan="2"><input name="submit" type="submit" value="Yes" /></td> </tr> </table> </form> <p><a href='index.php'>Index</a></p> <?php } else { ?> <form action="index.php" method="post"> <table> <tr> <th colspan="2">BAN IP</th> </tr> <tr> <td>IP</td><td><input name="ipaddress" type="text" size="20" maxlength="15" /></td> </tr> <tr> <td colspan="2"><input name="submit" type="submit" value="Ban" /></td> </tr> </table> </form> <hr width="55%" align="left"> <?php $count = mysql_query("SELECT count(id) FROM fdv_akobook_banned"); $ips = mysql_query("SELECT id,ip FROM fdv_akobook_banned order by id DESC"); $i = 1; echo '<table border="1" cellspacing="0"> <tr> <th width="10%">ID</th><th width="40%">IP</th> </tr> '; while ($field = mysql_fetch_assoc($ips)) { $colortr = $i % 2; if ($colortr==0) { $tr_style = 'style="background:#EEE"'; } else { $tr_style = 'style="background:#DDD"';} echo " <tr $tr_style>\n"; echo " <td>$field[id]</td>"; echo "<td><a href='index.php?ip=$field[ip]'>$field[ip]</a></td>\n </tr>\n"; $i++; }//end of ips echo "</table>\n";} } ?> </body> </html> |
i want to write a ban script because i get spam in my guestbook
Now is the problem that i cant put any new ip in the list because mysql says $result = 1. but it has to give an 0. does somebody knows where the error is? I dont get any errormessages from mysql.
Please help, because im ******* irritated.
thank you
edit: thx guys it works now.
to other ppl: above u see the corrected script
Last edited by devroom on Thu Jun 22, 2006 7:36 pm; edited 2 times in total
