justlukeyou Posted May 15, 2013 Share Posted May 15, 2013 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/ Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 isset means does it exist. Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430277 Share on other sites More sharing options...
justlukeyou Posted May 15, 2013 Author Share Posted May 15, 2013 Thanks, not totally sure what you mean by that. I think its actually better to hide the button, that should work better. Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430321 Share on other sites More sharing options...
requinix Posted May 16, 2013 Share Posted May 16, 2013 (edited) if (submit button was pressed && they are not trying to follow themselves) { add them as a follower to the other person; } Edited May 16, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430335 Share on other sites More sharing options...
justlukeyou Posted May 16, 2013 Author Share Posted May 16, 2013 Hi, This sounds complicated. I think I will try and hide the button for their own profile. If someone is not logged in I can also display the follow button but link it to the register page. That may be more intuitive. Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430402 Share on other sites More sharing options...
justlukeyou Posted May 16, 2013 Author Share Posted May 16, 2013 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430513 Share on other sites More sharing options...
requinix Posted May 16, 2013 Share Posted May 16, 2013 I am still stuck on how make the code block someone from following themselves.I didn't answer that? Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430515 Share on other sites More sharing options...
Jessica Posted May 16, 2013 Share Posted May 16, 2013 I didn't answer that?But you didn't do it with the EXACT code he can just copy-paste into his script, so he'll keep asking until someone supplies that. Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430530 Share on other sites More sharing options...
Q695 Posted May 18, 2013 Share Posted May 18, 2013 It's a "WHERE poster!=$your_own_id" on the database to prevent someone from following someone, or something like that. Quote Link to comment https://forums.phpfreaks.com/topic/278039-block-following-own-account/#findComment-1430847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.