Jump to content

wont uptade column


jBooker

Recommended Posts

Im trying to make a script that allows an admin to input the name of a character and ban his account.

the table characters has 'charname' and 'accountname'

the table accounts has 'username' and 'accesslevel'

the 'accountname' in characters matches the 'username' in accounts.

I want it to set the 'accesslevel' of the 'charname' whose 'accountname' matches 'username'.

 

This script will make it easier for my admins because they can only see the persons charname and in order to ban the person you need to know his accountname.

 

Heres the code:

if ($act == 'ban')
	{
		$success = $_GET["playerbaned"];
		if ($success == '1') { echo "Players account has been banned."; }
		else if ($success == '0') { echo "Player could not be banned."; }
		$query = mysql_query("SELECT * FROM accounts WHERE username = '$user'");
		$get = mysql_fetch_array($query);
		$access = $get['accesslevel'];
		if ($access >= $gmcplvl)
		{
			echo "<fieldset><legend>  <b>PLAYER BAN</b>  </legend>";
			echo "<b>Instructions</b>: Enter the character name and his/her accounts accesslevel will be set to 0 (banned). This can not be undone, yet..<br><br>";
			echo '<form method="post" action="index.php?a=doban">';
			echo '<b>Character name</b>: <input type="text" name="charban">';
			echo '<input type="submit" value="Ban Player" name="Ban Player">';
			echo '</form>';
			echo "</fieldset>";
		}
		ELSE if ($access < $gmcplvl)
		{
			echo "<center><h3>You do not have access to this feature.</h3></center>";
		}
	}
	if ($act == 'doban')
	{
		$chartoban = $_POST["charban"];
		if (!isSet($_POST["charban"]))
		{
			echo "<center><h3>No size specified. Please go back and input a size.</h3></center>";
		}
		else
		{
			$findchar = mysql_query("SELECT * FROM characters WHERE charname = '$chartoban'");
			$checkchar = mysql_num_rows($findchar);
			if ($checkchar == 0)
			{
				echo "<center><h3>Character could not be found</h3></center>";
			}
			else
			{
				$query = mysql_query("SELECT * FROM characters WHERE charname = '$chartoban'");
				$getacc = mysql_fetch_array($query);
				$account = $getacc['accountname'];
				$query = mysql_query("UPDATE accounts SET accesslevel = 0 WHERE username = $account");
				if (mysql_affected_rows() != 0)
				{
					unset($_POST["charban"]);
					header("Location: index.php?a=ban&playerbaned=1");
				}
				else
				{
					unset($_POST["charban"]);
					header("Location: index.php?a=ban&playerbaned=0");
				}
			}
		}
	}

 

I can't figure it out because when i test it it says "Players account has been banned." but when i look in the database the account is still accesslevel = 100 and not 0.

Link to comment
Share on other sites

Change this:

 

$query = mysql_query("UPDATE accounts SET accesslevel = 0 WHERE username = $account");

 

To this:

 

$query = mysql_query("UPDATE accounts SET accesslevel = 0 WHERE username = '$account'");

 

Your query was causing an error, but you weren't checking if it was causing an error. You can check for an error by writing your mysql_query()'s like this:

 

$query = mysql_query("UPDATE accounts SET accesslevel = 0 WHERE username = $account") or die(mysql_error());

 

Edit: and I'm guessing the reason mysql_affected_rows() wasn't zero was because of the SELECT query you did just before that. The UPDATE query had an error so it didn't change the number of affected rows from the last query.

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.