...

View Full Version : PLEASE help! Can't unban users!



ShadowIce
10-11-2009, 10:32 PM
Hi all. I'm having a bit of a problem w/ my code. This code keeps making it think the user in the banned table does not exist when I try to readd him to the unbanned table..

The problem I'm having is "* username does not exist"

when it clearly DOES exist, just in the banned table.

I tried flipping the mysql functions, but I guess that didnt fly..

Code:


/**
* procBanUser - If the submitted username is correct,
* the user is banned from the member system, which entails
* removing the username from the users table and adding
* it to the banned users table.
*/
function procBanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("banuser");

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Ban user from member system */
else{
$q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
$database->query($q);

$q = "INSERT INTO ".TBL_BANNED_USERS." VALUES ('$subuser', $session->time)";
$database->query($q);
header("Location: ".$session->referrer);
}
}

/**
* procUnbanUser - If the submitted username is correct,
* the user is unbanned from the member system, which entails
* removing the username from the banned table and adding
* it to the users table.
*/
function procUnbanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("unbanuser");

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Unban user from member system */

else{
$q = "DELETE FROM ".TBL_BANNED_USERS ." WHERE username = '$subuser'";
$database->query($q) or die(mysql_error());

$q = "INSERT INTO ".TBL_USERS ." VALUES ('$subuser', $session->time)";
$database->query($q) or die(mysql_error());
header("Location: ".$session->referrer);
}
}


ANY help is GREATLY appreciated! :)

Thanks!

mlseim
10-12-2009, 12:10 AM
This is just a long-shot ...

The only thing I can see that might make a difference is the extra spaces
where I have the red-x (indicating the spaces) that exist on the 2nd part
but not the first part ...

$q = "DELETE FROM ".TBL_BANNED_USERSx." WHERE username = '$subuser'";
$database->query($q) or die(mysql_error());

$q = "INSERT INTO ".TBL_USERSx." VALUES ('$subuser', $session->time)";

ShadowIce
10-12-2009, 12:49 AM
That didn't work..

The user still "doesn't exist" in the "banned" table.

But I know he does cuz im sittin' here lookin' at it..

*sigh*

Can anyone else help please?

ShadowIce
10-12-2009, 01:59 PM
anyone? :/

Sergey Popov
10-12-2009, 02:20 PM
Hi. Just a few thoughts:
1. You're referring to some error message "* username does not exist", but the code that generates this error message is not presented here. I think it is within function named checkUsername, can you post it here too?

2. In your INSERT queries, I would recommend to explicitly state which of fields are assigned in the VALUES() statement.
Because, if there were changes in the table structure either in TBL_BANNED_USERS or TBL_USERS - the result of your inserts might be unpredictable.

ShadowIce
10-12-2009, 02:31 PM
Right, here it is mate:



/**
* checkUsername - Helper function for the above processing,
* it makes sure the submitted username is valid, if not,
* it adds the appropritate error to the form.
*/
function checkUsername($uname, $ban=false){
global $database, $form;
/* Username error checking */
$subuser = $_POST[$uname];
$field = $uname; //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered<br>");
}
else{
/* Make sure username is in database */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$ban && !$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist<br>");
}
}
return $subuser;
}
};

Sergey Popov
10-12-2009, 02:59 PM
It is still not possible to locate problem with the given pieces of code. There are multiple cases when this error message will appear. You just need to debug this code on your environment and check what is happening. Particularly, I would try to detect first, which of criteria matches in this code, maybe usernameTaken, etc.:



if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$ban && !$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist<br>");
}

ShadowIce
10-12-2009, 03:08 PM
Right, new problem.

I edited checkusername() to have an $unban variable, and check for $unban.

I also changed the code anywhere it users checkusername() so that it works correctly w/ the given function.

it worked, but theres 1 small problem..

the problem is, when i unban someone, it unbans them, BUT deletes them at the same time.

alls i want it to do is delete the banned user from the banned table, and insert that user back into the unbanned table :)

code:



/**
* procBanUser - If the submitted username is correct,
* the user is banned from the member system, which entails
* removing the username from the users table and adding
* it to the banned users table.
*/
function procBanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("banuser", true, false);

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Ban user from member system */
else{
$q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
$database->query($q);

$q = "INSERT INTO ".TBL_BANNED_USERS." VALUES ('$subuser', $session->time)";
$database->query($q);
header("Location: ".$session->referrer);
}
}

/**
* procUnbanUser - If the submitted username is correct,
* the user is unbanned from the member system, which entails
* removing the username from the banned table and adding
* it to the users table.
*/
function procUnbanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("unbanuser", false, true);

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Unban user from member system */
else{
$q = "INSERT INTO ".TBL_USERS." VALUES ('$subuser', $session->time)";
$database->query($q);

$q = "DELETE FROM ".TBL_BANNED_USERS." WHERE username = '$subuser'";
$database->query($q);
header("Location: ".$session->referrer);
}

}

/**
* checkUsername - Helper function for the above processing,
* it makes sure the submitted username is valid, if not,
* it adds the appropritate error to the form.
*/
function checkUsername($uname, $ban=false, $unban=false){
global $database, $form;
/* Username error checking */
$subuser = $_POST[$uname];
$field = $uname; //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered<br>");
}
else{
/* Make sure username is in database */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$ban && !$unban && !$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist<br>");
}
}
return $subuser;
}
};

ShadowIce
10-12-2009, 03:25 PM
When I add or die("Error: ".mysql_error()) to $database->query($q),

it returns this for procUnbanUser():



Error: Column count doesn't match value count at row 1


Any idea how to fix?

ANY help would be GREATLY appreciated! :)

Thanks!

ShadowIce
10-12-2009, 08:52 PM
anyone? :/

ShadowIce
10-13-2009, 08:18 PM
its driving me CRAZY! :/ i dont see anything wrong w/ the code (i think), yet it DELETES my user..

ShadowIce
10-14-2009, 07:16 PM
Ok, I fixed the ban problem. Now I'm having problem w/ unban. Everytime I enter a username into the unban field, and try to unban it, it says '* Username not entered' which is SO not correct..

WtF am I doing wrong in procUnbanuser() ?



/**
* procBanUser - If the submitted username is correct,
* the user is banned from the member system, which entails
* removing the username from the users table and adding
* it to the banned users table.
*/
function procBanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("banuser", true, false);

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Ban user from member system */
else{
$q = "INSERT INTO banned_users (username, userlevel, email, timestamp)"
." VALUES('$subuser', '$session->updlevel', '$subemail', '$session->time')";
$database->query($q) or die(mysql_error());

$q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
$database->query($q) or die(mysql_error());
header("Location: ".$session->referrer);
}
}

/**
* procUnbanUser - If the submitted username is correct,
* the user is unbanned from the member system, which entails
* removing the username from the banned table and adding
* it to the users table.
*/
function procUnbanUser(){
global $session, $database, $form;
/* Username error checking */
$subuser = $this->checkUsername("unbanuser", false, true);

/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Unban user from member system */
else{
$q = "INSERT INTO users (username, userlevel, email, timestamp)"
." VALUES('$subuser', '$session->updlevel', '$subemail', '$session->time')";
// echo $q;
$database->query($q) or die(mysql_error());

$q = "DELETE FROM ".TBL_BANNED_USERS." WHERE username = '$subuser'";
// echo $q;
$database->query($q) or die(mysql_error());
header("Location: ".$session->referrer);
}
}

AdNetMart.com
10-15-2009, 10:59 AM
Ok, I fixed the ban problem. Now I'm having problem w/ unban. Everytime I enter a username into the unban field, and try to unban it, it says '* Username not entered' which is SO not correct..

WtF am I doing wrong in procUnbanuser() ?

I'd check if this:


function checkUsername($uname, $ban=false, $unban=false)

has something to do with it.


/* Username error checking */
$subuser = $this->checkUsername("banuser", true, false);

ShadowIce
10-15-2009, 02:06 PM
Right. I see what u mean.

its returning 'banuser' even in the unban input box...

which is weird.. so yea.

adminprocess.php username code:



/**
* checkUsername - Helper function for the above processing,
* it makes sure the submitted username is valid, if not,
* it adds the appropritate error to the form.
*/
function checkUsername($uname="", $ban=false, $unban=false){
global $database, $form;
/* Username error checking */
$subuser = $_POST[$uname];
$field = $uname; //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
echo $uname;
$form->setError($field, "* Username not entered<br>");
}
else{
/* Make sure username is in database */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$ban || !$unban && !$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist<br>");
}
}
return $subuser;
}
};


admin.php (input):



<?
/**
* Admin.php
*
* This is the Admin Center page. Only administrators
* are allowed to view this page. This page displays the
* database table of users and banned users. Admins can
* choose to delete specific users, delete inactive users,
* ban users, update user levels, etc.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 26, 2004
*/
require("../include/session.php");

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
global $database;
$q = "SELECT username,userlevel,email,timestamp "
."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows = mysql_numrows($result);
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
return;
}
if($num_rows == 0){
echo "Database table empty";
return;
}
/* Display table contents */
echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
for($i=0; $i<$num_rows; $i++){
$uname = mysql_result($result,$i,"username");
$ulevel = mysql_result($result,$i,"userlevel");
$email = mysql_result($result,$i,"email");
$time = mysql_result($result,$i,"timestamp");

echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
}
echo "</table><br>\n";
}

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayBannedUsers(){
global $database;
$q = "SELECT username,userlevel,email,timestamp "
."FROM ".TBL_BANNED_USERS." ORDER BY userlevel DESC,username";
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows = mysql_numrows($result);
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
return;
}
if($num_rows == 0){
echo "Database table empty";
return;
}
/* Display table contents */
echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Time Banned</b></td></tr>\n";
for($i=0; $i<$num_rows; $i++){
$uname = mysql_result($result,$i,"username");
$ulevel = mysql_result($result,$i,"userlevel");
$email = mysql_result($result,$i,"email");
$time = mysql_result($result,$i,"timestamp");

echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
}
echo "</table><br>\n";
}

/**
* User not an administrator, redirect to main page
* automatically.
*/
if (!($session->isShadowMaster() || $session->isSuperAdmin())) {
header("Location:../index.php");
}
else{
/**
* Administrator is viewing page, so display all
* forms.
*/
?>
<html>
<title>ShadowIce Login - Admin</title>
<body oncontextmenu="return false" onbeforecut="return false" onbeforepaste="return false" oncut="return false" onpaste="return false">
<style type="text/css">
body
{
font-family:verdana;
background: #212121 url('../bg/FF10-tidus-yuna.jpg') no-repeat fixed top-center 10px 5px;
}
.logintbl{
position:absolute;
top: 10;
left: 10;
}
#logintbl{
position:absolute;
top: 10;
left: 10;
}
.logintbl1{
position:absolute;
top: 10;
left: 10;
}
#logintbl1{
position:absolute;
top: 10;
left: 10;
}
input{
background-color: #767676;
color: #B4B4B4;
border: 1;
border-Color: black;
}
</style>
<table style="background-Color: #212121;" borderColor="#000000" border="1" name="admintbl" id="admintbl1" cellpadding="0" cellspacing="0" valign="top">
<td>
<h1>Admin Center</h1>
<font size="5" color="#ff0000">
<b>::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</b></font><br><br>
<?php
require("menu.php");
if($session->isShadowMaster()){
require("sm_adminmenu.php");
}
?>
<br><br>
[<a href="../index.php">Back to Main Page</a>]
<br><br>
<?php
if($database->num_active_guests == 1){
$guestname = "guest";
}else{
$guestname = "guests";
}
echo "</td></tr><tr><td align=\"center\"><br><br>";
echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
if($database->num_active_users != 1){
$isorare = "are";
$regmem = "members";
}else{
$isorare = "is";
$regmem = "member";
}
echo "There $isorare $database->num_active_users registered $regmem and ";
echo "$database->num_active_guests $guestname viewing the site.<br><br>";
require("../include/view_active.php");
echo "<br>";
echo "<hr>";
?>
<br>
<?
if($form->num_errors > 0){
echo "<font size=\"4\" color=\"#ff0000\">"
."!*** Error with request, please fix</font><br><br>";
}
?>
<table align="left" border="0" cellspacing="5" cellpadding="5">
<tr><td>
<?
/**
* Display Users Table
*/
?>
<h3>Users Table Contents:</h3>
<?
displayUsers();
?>
</td></tr>
<tr>
<td>
<br>
<?
/**
* Update User Level
*/
?>
<h3>Update User Level</h3>
<? echo $form->error("upduser"); ?>
<table>
<form action="adminprocess.php" method="POST">
<tr><td>
Username:<br>
<input type="text" name="upduser" maxlength="30" value="<? echo $form->value("upduser"); ?>">
</td>
<td>
Level:<br>
<select name="updlevel">
<script>
for(var x=1; x<=10;x++){
document.write("<option value=\""+x+"\">"+x+"</option>");
}
</script>
</select>
</td>
<td>
<br>
<input type="hidden" name="subupdlevel" value="1">
<input type="submit" value="Update Level">
</td></tr>
</form>
</table>
</td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>
<?
/**
* Delete User
*/
?>
<h3>Delete User</h3>
<? echo $form->error("deluser"); ?>
<form action="adminprocess.php" method="POST">
Username:<br>
<input type="text" name="deluser" maxlength="30" value="<? echo $form->value("deluser"); ?>">
<input type="hidden" name="subdeluser" value="1">
<input type="submit" value="Delete User">
</form>
</td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>
<?
/**
* Delete Inactive Users
*/
?>
<h3>Delete Inactive Users</h3>
This will delete all users (not administrators), who have not logged in to the site<br>
within a certain time period. You specify the days spent inactive.<br><br>
<table>
<form action="adminprocess.php" method="POST">
<tr><td>
Days:<br>
<select name="inactdays">
<option value="3">3
<option value="7">7
<option value="14">14
<option value="30">30
<option value="100">100
<option value="365">365
</select>
</td>
<td>
<br>
<input type="hidden" name="subdelinact" value="1">
<input type="submit" value="Delete All Inactive">
</td>
</form>
</table>
</td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>
<?
/**
* Ban User
*/
?>
<h3>Ban User</h3>
<form action="adminprocess.php" method="POST">
<? echo $form->error("banuser"); ?>
Username:<br>
<input type="text" name="banuser" maxlength="30" value="<? echo $form->value("banuser"); ?>">
<input type="hidden" name="subbanuser" value="1">
<input type="submit" value="Ban User">
<?
/**
* Unban User
*/
?>
<h3>Unban User</h3>
<? echo $form->error("unbanuser"); ?>
Username:<br>
<input type="text" name="unbanuser" maxlength="30" value="<? echo $form->value("unbanuser"); ?>">
<input type="hidden" name="subunbanuser" value="1">
<input type="submit" value="Unban User">
</form>
</td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr><td>
<?
/**
* Display Banned Users Table
*/
?>
<h3>Banned Users Table Contents:</h3>
<?
displayBannedUsers();
?>
</td></tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>
<?php
/**
* Delete Banned User
*/
?>
<h3>Delete Banned User</h3>
<? echo $form->error("delbanuser"); ?>
<form action="adminprocess.php" method="POST">
Username:<br>
<input type="text" name="delbanuser" maxlength="30" value="<? echo $form->value("delbanuser"); ?>">
<input type="hidden" name="subdelbanned" value="1">
<input type="submit" value="Delete Banned User">
</form>
</td>
</tr>
</table>
</body>
</html>
<?php
}
?>


I just dont get it..

ANY help would be GREATLY appreciated! :)

ShadowIce
10-15-2009, 04:37 PM
Can someone please help?

:/

ShadowIce
10-17-2009, 02:27 PM
meh..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum