How to enable and disable friend requests (Help Please)

Ben144

Member
Jan 31, 2017
76
5
Hey,

I have created a simple settings page for the FluxRP Emulator ect and I have added an option for when a player click on the relevant button, then it will either disable or enable friend requests ect, but it is not working as when i add the php code, then the cms just breaks and when i remove the code, then the button doesn't work at all.

Code:
<div class="content-box">
            <div class="title">Friend Requests</div>
            <div class="box-content d-flex justify-content-center align-items-center">
                                    <?php

    if (isset($_POST['profileForm'])) {
        
        $efr = filter($_POST['friendRequestsAllowed']);
        
        if ($efr == 1) {
            
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Disabled</b></div>'
            
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
            
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Enabled</b></div>'
            
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
                <div class="mr-3">
                    <form method="post" id="profileForm" class="form-block">
                        <input type="hidden" name="_token" value="4e26eaf44aedd954ff26441a92b2b42bbe4d1ada">
                        <input type="hidden" name="block_friend_requests" value="" value="true">
                        <?php

    if (isset($_POST['profileForm'])) {
        
        $efr = filter($_POST['friendRequestsAllowed']);
        
        if ($efr == 1) {
            
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Disable</button>'
            
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
            
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Enabled</button>'
            
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
                    </form>

Any help appreciated and thanks in advance
 

Hypothesis

Programmer
Jan 6, 2019
524
361
Your code runs fine, you were just missing semicolons after your echo statements. Although, I will say this isn't a very good way to update things in your database. Could be a security problem, recommended that you move this into your class.users.php and have it all update from there.
PHP:
<div class="content-box">
            <div class="title">Friend Requests</div>
            <div class="box-content d-flex justify-content-center align-items-center">
    <?php

    if (isset($_POST['profileForm'])) {
       
        $efr = filter($_POST['friendRequestsAllowed']);
       
        if ($efr == 1) {
           
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Disabled</b></div>';
           
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
           
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Enabled</b></div>';
           
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
                <div class="mr-3">
                    <form method="post" id="profileForm" class="form-block">
                        <input type="hidden" name="_token" value="4e26eaf44aedd954ff26441a92b2b42bbe4d1ada">
                        <input type="hidden" name="block_friend_requests" value="" value="true">
                        <?php

    if (isset($_POST['profileForm'])) {
       
        $efr = filter($_POST['friendRequestsAllowed']);
       
        if ($efr == 1) {
           
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Disable</button>';
           
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
           
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Enabled</button>';
           
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
</form>
 

Ben144

Member
Jan 31, 2017
76
5
Your code runs fine, you were just missing semicolons after your echo statements. Although, I will say this isn't a very good way to update things in your database. Could be a security problem, recommended that you move this into your class.users.php and have it all update from there.
PHP:
<div class="content-box">
            <div class="title">Friend Requests</div>
            <div class="box-content d-flex justify-content-center align-items-center">
    <?php

    if (isset($_POST['profileForm'])) {
      
        $efr = filter($_POST['friendRequestsAllowed']);
      
        if ($efr == 1) {
          
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Disabled</b></div>';
          
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
          
            echo '<div class="ml-3 mr-auto">You currently have friend requests <b>Enabled</b></div>';
          
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
                <div class="mr-3">
                    <form method="post" id="profileForm" class="form-block">
                        <input type="hidden" name="_token" value="4e26eaf44aedd954ff26441a92b2b42bbe4d1ada">
                        <input type="hidden" name="block_friend_requests" value="" value="true">
                        <?php

    if (isset($_POST['profileForm'])) {
      
        $efr = filter($_POST['friendRequestsAllowed']);
      
        if ($efr == 1) {
          
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Disable</button>';
          
            mysql_query("UPDATE users SET block_newfriends = '0' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
        else if ($efr == 0) {
          
            echo '<button type="submit"  name="friendRequestsAllowed" class="button green">Enabled</button>';
          
            mysql_query("UPDATE users SET block_newfriends = '1' WHERE id = '" . $_SESSION['user']['id'] . "'");
        }
    }

?>
</form>
Cheers, but is it only the php code that i place in class.users.php and do I keep the html code where it is :/
 

Users who are viewing this thread

Top