Jump to content

Archived

This topic is now archived and is closed to further replies.

Rosst

ip ban script causing 500 error

Recommended Posts

Please help, my ip banning script is causing a 500 error, here is the script:
[code]<? include "site_top.php"; ?>
<?php
require("config.php");
switch ($_GET[id]) {
default:
if(!isset($_POST[ban])){ // If the submit button hasnt been pressed
echo "<form method='post'>
<b>IP Address:</b><br>
<input type='text' name='ip' maxlength='50'>
<br>
<b>Reason:</b>
<br>
<textarea name='reason' cols='30' rows='5'></textarea>
<br>
<input type='submit' name='ban' value='Ban IP'>
</form>";
}
if($_POST[ban]){ // If the submit button is pressed
$ip = $_POST['ip']; //Get the name field
$reason = $_POST['reason'];//Get the message filed
if($ip == NULL || $reason == NULL){ // If either fields are left blank..
echo "A field was left blank, please go back and fix this."; //Echo a field was left blank.
}else{ // If neither fields are blank...
$postcmt = mysql_query("INSERT INTO `banned` (ip,reason,by) VALUES ('$ip','$reason','$logged[username]')"); //Insert the shout
echo "The IP has been banned."; // Echo shout was posted
}
}
$listbans = mysql_num_rows(mysql_query("SELECT * FROM banned ORDER BY id DESC"));
if ($listbans < 1) {
echo "<br />No bans have been made";
}
else {
$bans = mysql_fetch_array(mysql_query("SELECT * FROM banned ORDER BY id DESC"));
while ($b = $bans) {
echo "<br />IP: $b[ip]<br />Reason: $b[reason]<br />By: $b[by]-----<a href=\"ipban.php?id=delete&ip=$b[ip]\">DELETE</a><br />";
}
}
break;
case 'delete':
if (!$_GET[ans] && $_GET[ip]) {
echo "Are you sure you want to delete this ban? <a href=\"ipban.php?id=delete&ans=yes\">Yes</a> Or <a href=\"ipban.php?id=delete&ans=no\">No</a>?";
}
elseif ($_GET[ans] == no && $_GET[ip]) {
echo "You desided to keep the ban";
}
elseif ($_GET[ans] == yes && $_GET[ip]) {
echo "Deleting ban...........";
$delete = mysql_query("DELETE FROM banned WHERE ip = '$_GET[ip]'");
echo "Ban deleted!!";
}
else {
echo "You have reached a invalid page";
}
break;
}
?>
<? include "site_bot.php"; ?>[/code]

Share this post


Link to post
Share on other sites
The best way(that I know of) to set up a switch statment is like this.

[code]
<?php
include("whatever.php");

function showpage($page) {
     switch ($page) {
         case "case 1":
         //some code here
         break;
         case "case 2":
         break;
     default:
     //your default code goes here
     }
}
showpage($_GET['page']);//you need this to execute your code
?>
[/code]

Now you can link to this like this [b]whatever.php?page=case1[/b]

Share this post


Link to post
Share on other sites
I don't care the best way to do a switch statment, can you help me or not

Share this post


Link to post
Share on other sites
[quote author=Rosst link=topic=104163.msg415304#msg415304 date=1155540250]
I don't care the best way to do a switch statment, can you help me or not
[/quote]

With an attitude like that I most certainly will not and I doubt that anyone else will ether.

Share this post


Link to post
Share on other sites

×

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.