Jump to content

Block Following Own Account


justlukeyou

Recommended Posts

Hi,

 

I have been trying to set up a social networking button and I have almost completed. However I have approached it from a wrong angle and have one last piece to finish.

 

I can click the "Follow" button and it instantly swaps to "Following" button. It refreshes the page and displays that the user is now following the profile. However the code currently allows someone to follow their own profile. The problem is I dont know how to stop this.

 

I need something which says if $profileid = $followerid dont run code.

 

Does anyone have any suggestions please on how I an prevent this from happening.

 

Alternatively I could hide the follow button if the user is logged in on their own profile but I am stuck on how to do this also.

 

 

<?php
 
$profileid = (int)$_GET['ID'];
$followerid = intval($_SESSION['userID']);



$query = mysql_query("SELECT * FROM follow WHERE user_id = '". $profileid ."' AND follow_user_id= '". $followerid ."'"); 
$duplicatefollow = null;
if (mysql_num_rows($query) > 0) 
{ 
$error['duplicatefollow'] = ''; 
}   



else
{
  
if(isset($_POST['followbutton'])) {


$query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')";
$result = mysql_query($query);



}  
}     
  


  
  $loginprofile = intval($_SESSION['userID']); 
  
  $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
$rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
  
?>

   

 
 <?php
$query = mysql_query("SELECT * FROM follow WHERE user_id = '". $profileid ."' AND follow_user_id= '". $followerid ."'"); 
$duplicatefollow = null;
if (mysql_num_rows($query) > 0) 
{ 
echo '<div class="followbuttonboxsuccess"><img src="/images/following.png" /></div>'; 
} 
else
{
echo '<div class="followbuttonbox"><input name="followbutton" CLASS="submitbutton" type="submit" /></div>'; 
}
?> 
Link to comment
Share on other sites

Hi,

 

I have managed to edit the code so that it displays a different image if someone is or is not logged in. This helps massively.

 

I am still stuck on how make the code block someone from following themselves.

 

 

 

 

<form method="post" enctype="multipart/form-data">

<?php
 
$profileid = (int)$_GET['ID'];
$followerid = intval($_SESSION['userID']);



$query = mysql_query("SELECT * FROM follow WHERE user_id = '". $profileid ."' AND follow_user_id= '". $followerid ."'"); 
$duplicatefollow = null;
if (mysql_num_rows($query) > 0) 
{ 
$error['duplicatefollow'] = ''; 
}   



else
{
  
if(isset($_POST['followbutton'])) {


$query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')";
$result = mysql_query($query);



}  
}     
  


  
  $loginprofile = intval($_SESSION['userID']); 
  
  $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
$rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
  
?>

   
		 <?php
	     if ($_SESSION['userLoggedIn'])
{ ?>
   <?php
$query = mysql_query("SELECT * FROM follow WHERE user_id = '". $profileid ."' AND follow_user_id= '". $followerid ."'"); 
$duplicatefollow = null;
if (mysql_num_rows($query) > 0) 
{ 
echo '<div class="followbuttonboxsuccess"><img src="/images/following.png" /></div>'; 
} 
else
{
echo '<div class="followbuttonbox"><input name="followbutton" CLASS="submitbutton" type="submit" /></div>'; 
}
?> 

</form>	 <?php
  ;
} else { 
 ?>
 
<div class="followbuttonbox"><a href="/users/register.php"  rel="nofollow" ><img src="/images/follow.png" /></a></div>

<?php
	  }
	  
    
    ?>  
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.