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
https://forums.phpfreaks.com/topic/278039-block-following-own-account/
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
	  }
	  
    
    ?>  

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.