Jump to content

ip ban script causing 500 error


Rosst

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]
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

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.