Titan85
07-10-2007, 12:19 AM
Hello, I am trying to make a user ban script that you can either enter the username or IP and it will ban the user. When baning by username, I want it get the ip of the user out of the user list and thats where I run into problems. All the data goes through but for some reason, it never gets the value of $ip. Here is my code:
<?php
########## If Ban Hit ##########
if ($_POST['ban']) {
$reason = mysql_real_escape_string($_POST['reason']);
$ban = $_POST['ban'];
$date = date('n/j/y');
// If ban by username
if ($_POST['type'] == 'user') {
$get = mysql_query("SELECT ip FROM `users` WHERE user = '$ban'") or die ("Error Getting IP! \n<br />\n" .mysql_error());
$u = mysql_fetch_array($get); $ip = $u['ip'];
} else { $ip = mysql_real_escape_string($_POST['ip']); }
//
$insert = mysql_query("INSERT INTO `ban` (id, reason, ip, date) VALUES ('', '$reason', '$ip', '$date')") or die ("Error Banning User! \n<br />\n" .mysql_error());
echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">'.$ip.' The user has been banned.</div>');
}
########## If Ban Not Hit ##########
if (!$_POST['ban']) { ?>
<!-- Ban User Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="300" align="center">
<tr>
<td>Ban By:</td>
<td>
<select name="type">
<option selected="selected" value="ip">IP</option>
<option value="user">Username</option>
</select>
</td>
</tr>
<tr>
<td>IP/Username:</td>
<td><input type="text" name="ban" /></td>
</tr>
<tr>
<td>Reason:</td>
<td><input type="text" name="reason" maxlength="80" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="ban" value="Ban" /></td>
</tr>
</table>
</form>
<!-- /Ban User Form -->
<? }
?>I think the query for getting the ip data is returning nothing, but I know that there is indeed an entry for "ip" in the user table for that username. Any ideas? Thanks
<?php
########## If Ban Hit ##########
if ($_POST['ban']) {
$reason = mysql_real_escape_string($_POST['reason']);
$ban = $_POST['ban'];
$date = date('n/j/y');
// If ban by username
if ($_POST['type'] == 'user') {
$get = mysql_query("SELECT ip FROM `users` WHERE user = '$ban'") or die ("Error Getting IP! \n<br />\n" .mysql_error());
$u = mysql_fetch_array($get); $ip = $u['ip'];
} else { $ip = mysql_real_escape_string($_POST['ip']); }
//
$insert = mysql_query("INSERT INTO `ban` (id, reason, ip, date) VALUES ('', '$reason', '$ip', '$date')") or die ("Error Banning User! \n<br />\n" .mysql_error());
echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">'.$ip.' The user has been banned.</div>');
}
########## If Ban Not Hit ##########
if (!$_POST['ban']) { ?>
<!-- Ban User Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="300" align="center">
<tr>
<td>Ban By:</td>
<td>
<select name="type">
<option selected="selected" value="ip">IP</option>
<option value="user">Username</option>
</select>
</td>
</tr>
<tr>
<td>IP/Username:</td>
<td><input type="text" name="ban" /></td>
</tr>
<tr>
<td>Reason:</td>
<td><input type="text" name="reason" maxlength="80" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="ban" value="Ban" /></td>
</tr>
</table>
</form>
<!-- /Ban User Form -->
<? }
?>I think the query for getting the ip data is returning nothing, but I know that there is indeed an entry for "ip" in the user table for that username. Any ideas? Thanks