jBooker Posted November 2, 2008 Share Posted November 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted November 2, 2008 Share Posted November 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
jBooker Posted November 2, 2008 Author Share Posted November 2, 2008 Thank you very much for your help. Problem solved =] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.