Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Block Following Own Account

$
0
0
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>'; 
}
?> 

Viewing all articles
Browse latest Browse all 13200

Trending Articles