I have 2 dbs that are important here - systemmsg (system messages) and friendrequests (containing all friends/pending/declined requests).
Here is the main code that I'm using for this script:
if(isset($invitefriend)){
if(!empty($invitefriendname)){
    if($invitefriendname !== $sessionname){
        $sqlcheckforrequest = "SELECT * FROM friendrequests WHERE sendername='$sessionname' AND recipientname='$invitefriendname'";
        $resultcheckforrequest = mysqli_query($conn, $sqlcheckforrequest);
        if(mysqli_num_rows($resultcheckforrequest) == 0){
            $sqlscheckforusername = "SELECT * FROM registered WHERE userName='$invitefriendname'";
            $resultcheckforusernamesql = mysqli_query($conn, $sqlscheckforusername);
            if(mysqli_num_rows($resultcheckforusernamesql) !== 0){
                while($reqfriend = mysqli_fetch_array($resultcheckforusernamesql)){
                    $frsendid = $reqfriend['id'];
                    $frsendname = $reqfriend['userName'];
                }
                $sqlsendrequest = "INSERT INTO friendrequests (senderid,recipientid,sendername,recipientname,status) VALUES ('$sessionid','$frsendid','$sessionname','$frsendname','0')";
                $resultsendrequest = mysqli_query($conn, $sqlsendrequest);
                if($resultsendrequest == true){
                    if($rights = 0){
                        $myusernamefriendupdate = "<a href=\'profile.php?id=$sessionid\' class=\'u-onsys\'>$sessionname</a>";
                    }
                    if($rights = 1){
                        $myusernamefriendupdate = "<a href=\'profile.php?id=$sessionid\' class=\'cmod-onsys\'>$sessionname</a>";
                    } 
                    if($rights = 2){
                        $myusernamefriendupdate = "<a href=\'profile.php?id=$sessionid\' class=\'mod-onsys\'>$sessionname</a>";
                    }
                    if($rights = 3){
                        $myusernamefriendupdate = "<a href=\'profile.php?id=$sessionid\' class=\'adm-onsys\'>$sessionname</a>";
                    }
                    if($rights = 4){
                        $myusernamefriendupdate = "<a href=\'profile.php?id=$sessionid\' class=\'root-onsys\'>$sessionname</a>";
                    }
                $systemmessage = "$myusernamefriendupdate invited you to become his friend.";
                $systemtitle = "Friend request";
                $sqlupdatesystemmessage = "INSERT INTO systemmsg (systemtitle, systemto, systemtext) VALUES ('$systemtitle','$frsendname','$systemmessage')";
                mysqli_query($conn, $sqlupdatesystemmessage);
                $countsystemmessages++;
                $invitefrerror = "Success";
                }
            } else {
                $invitefrerror = "We couldn't find that username";
            }
        } else {
            $invitefrerror = "You already invited this user";
        }
    } else {
        $invitefrerror = "Inviting yourself";
    }
} else {
    $invitefrerror = "Empty";
}
}
So the script should work that way:
User 1 sends friend request to User 2, User 2 receives system message saying: usericon(variable by the user rights that has sent the requests)Username has send you an invitation. (or whatever)
We have a normal form containing 2 inputs text and submit. We have selected our session rights from the db registered (users) and it's
$rights = $row['rights'];
Before I click "Send request" my (the session rights) are working fine (getting the real number from the db (0 for user, 1 for chat moderator, 2 for moderator, 3 for admin and 4 for root). But when I click that little cheeky button, the rights are changing to a constant number (4 in this example) and it's showing an invitation from a normal user for example with the root icon. I don't know how to fix that and where the actual mistake is.
I hope most of you can understand my question, because there is literally no one else to ask other than you at the moment.
Thanks for your time!
 
     
     
    