0

I've been doing some work on my website control panel for a game I'm working on. But I can't seem to get the "Ban!" button to be "Unban!" if the result $row['banned'] is FALSE. I get it to output TRUE : FALSE depending on what it says in the table.

Any help getting this fixed would be greatly appreciated. I have struggled with this for a few days now and I felt like giving up once or twice but this has to be completed to help the admins on my game have it easier to check banned accounts and control the options.

p.s "connect.php" only has a few variables that are used and the mysql connect string.

<?php 
require('connect.php');

if(isset($_POST['ban'])){
   $id = $_POST['ban_rec_id'];  
   $query = "UPDATE accounts SET banned=1 WHERE id=$id"; 
   $result = mysql_query($query);
}else if(isset($_POST['unban'])){
   $id = $_POST['unban_rec_id'];
   $query = "UPDATE accounts SET banned=0 WHERE id=$id";
   $result = mysql_query($query);
}

$query = "SELECT id, uuid, name, REPLACE(REPLACE(banned,'0','FALSE'),'1','TRUE') AS banned FROM accounts ORDER BY id ASC";
$result = mysql_query($query);
echo "<center>
    <table>
    <tr>
        <th>Acccount Id</th>
        <th>Username</th>
        <th>In-Game Name</th>
        <th>Banned</th>";
        if($ban === true){
            echo "<th>Ban</th>";
        }
echo "</tr>";
while ($row = mysql_fetch_array($result)) {
        $id = $row['id'];
    $username = $row['uuid'];
    $gamename = $row['name'];
    $banned = $row['banned'];

    echo "<tr>";
    echo "<td>" . $id . "</td>";
    echo "<td>" . $username . "</td>";
echo "<td>" . $gamename . "</td>";
    echo "<td>" . $banned . "</td>";
    if($ban === true){
        if($row['banned'] == FALSE){
            echo "<td>"?>
            <form id="ban" method="post" action="">
                <input type="hidden" name="ban_rec_id" value="<?php print $id; ?>"/>
                <input class="button-small" type="submit" name="ban" value="Ban!"/>
            </form>
            <?php "</td>";
        } else {
            echo "<td>"?>
            <form id="unban" method="post" action="">
                <input type="hidden" name="unban_rec_id" value="<?php print $id; ?>"/>
                <input class="button-small" type="submit" name="unban" value="Unban!"/>
            </form>
            <?php "</td>";
        }
    }
    echo "</tr>";
}
echo "</table></center>";
mysql_close($link);
?>
2

2 Answers 2

1

Try use string for FALSE instead since looks like you might have assigned it with String rather than Boolean value in your error-prone REPLACE(REPLACE(banned,'0','FALSE'),'1','TRUE'):

if($row['banned'] == 'FALSE')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've been really tired lately. I think I've been up for about 2 days now just working on this. It's awkward to miss something so simple in it. I think it'd be better for me to go to bed and get some sleep now. It fixed the system btw. Thanks :)
0

So what actually is the problem with that? The code seems to be fine, in case the value in 'banned' column is false or true. But you should check the right value type in your columns. If it is string (varchar, text etc) that is saying 'FALSE' or 'TRUE' you should use 'FALSE' instead of FALSE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.