473,549 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

follow user system

19 New Member
Here I made a another attempt to create a follow user system. I used a table follow_user which has fid as primary key set to Auto_increment and two more columns user_id for id of user to be followed and id_fk for id of user following.

Follow/unfollow button works fine and data gets stored in db but problem is both id_fk and user_id display 0 where they should display id's of user following and user followed instead.

My code is

profile.php
Expand|Select|Wrap|Line Numbers
  1.   <div class="follow_box">
  2.    <?php
  3.     if(is_loggedin()){
  4.      $id = $_SESSION['user_login'];
  5.      $userid = $user;
  6.      if($user !=$_SESSION['user_login']) {
  7.      $follow_check="SELECT * from follow_user WHERE id_fk='$id' and user_id='$userid' ";
  8.      $user_sql=mysql_query($follow_check);
  9.      $count=mysql_num_rows($user_sql);
  10.      if($count==0){
  11.       echo "<div id='follow$userid'><a href='' class='follow' id='$userid' style='text-decoration:none;background-color:#3399FF'><span class='btn' style='width:70px;'><b> Follow </b></span></a></div>";
  12.       echo"<div id='remove$userid' style='display:none'><a href='#' class='remove' id='$userid' style='text-decoration:none;'><span class='btn btn-info' style='width:70px;'><b> Following </b></span></a></div>";
  13.       }
  14.       else{
  15.       echo "<div id='follow$userid' style='display:none'><a href='' class='follow' id='$userid'><span class='btn' style='width:70px;'><b> Follow </b></span></a></div>";
  16.       echo"<div id='remove$userid'><a href='#' class='remove' id='$userid'><span class='btn btn-info' style='width:70px;'><b> Following </b></span></a></div>";
  17.       }
  18.       }
  19.       }
  20.        else{
  21.        echo "You must be logged in to view stuff and things";
  22.       }
  23.       ?>
follow.js
Expand|Select|Wrap|Line Numbers
  1.    $(function() {
  2.    $(".follow").click(function(){
  3.    var user_id = $(this).attr("id");
  4.    var datastring = 'user_id='+ user_id ;
  5.    $.ajax({
  6.    type: "POST",
  7.    url: "add_follow_user.php",
  8.    data: datastring,
  9.    success: function(html){}
  10.    });
  11.    $("#follow"+user_id).hide();
  12.    $("#remove"+user_id).show();
  13.    return false;
  14.    });
  15.    });
  16.    $(function() {
  17.    $(".remove").click(function(){
  18.    var user_id = $(this).attr("id");
  19.    var datastring = 'user_id='+ user_id ;
  20.    $.ajax({
  21.    type: "POST",
  22.    url: "remove_follow_user.php",
  23.    data: datastring,
  24.    success: function(html){}
  25.     });
  26.    $("#remove"+user_id).hide();
  27.    $("#follow"+user_id).show();
  28.    return false;
  29.    });
  30.    });
  31.    </div>
add_follow_user .php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include ( "./inc/header.inc.php" ); 
  3.     if($_POST['user_id']){
  4.     $user_id=$_POST['user_id'];
  5.     $user_id = mysql_escape_String($user_id);
  6.     $sql_in = "INSERT INTO follow_user(id_fk,user_id) VALUES ('$id','$user_id')";
  7.     mysql_query( $sql_in);
  8.     }
  9.     ?>
remove_follow_u ser.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include ( "./inc/header.inc.php" ); 
  3.     if($_POST['user_id']){
  4.     $user_id=$_POST['user_id'];
  5.     $user_id = mysql_escape_String($user_id);
  6.     $sql_in = mysql_query("DELETE FROM follow_user WHERE id_fk='$id' AND user_id='$user_id'");
  7.     }
  8.     ?>
Sep 20 '15 #1
0 1223

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1542
by: Splashout | last post by:
I am in the process of building a multi user system that I envisage running of a server with client DB's using linked tables. Is there anyway to force the client DB's to update these tables at a set period of time? Or is there a better way to go about this? Many Thanks Glyn
0
1805
by: Anurag | last post by:
Hi, ENV: DB2 ESE 8.2.3 DPF (11 nodes) on AIX 5.x ==== SCENARIO / SETUP ======== ====== (1) I needed to find out CPU Time (User / System) of SQL queries for benchmark testing. (2) I setup an EVENT MONITOR WHERE AUTH_ID = 'ANURAG' (write to table).
45
2659
by: Luvin lunch | last post by:
Hi, I'm new to Access and have been asked to develop a simple Access system to replace one that already exists. There are five users of the current Access system and each of the users works off a copy of the system on their local machines. I would like to develop my new system as a multi-user system and place it on a server to be...
1
1981
by: Mike1234 | last post by:
I have an MS Access Order Entry system running for about 2 years and want to put it on the office LAN to make it multi user (3 users max) system. We are running Access 2003 on XP Professional. The system has about 1500 lines of VBA code and uses automation to generate reports in Microsoft Word. What is the best way to accomplish this?
2
1176
by: patr0805 | last post by:
I have created a user system, but I just cant find out how to make new users in the database.mdb (MS Access) file with php, asp or html
30
3133
by: Yorian | last post by:
Hey, Although I've been using classes and object for quite a while now I've never actually programmed proper OO code yet. It ofcourse depends on what you call proper OO code. I have been seperating parts of the website. Like a user class, guestbook class, etc. But I've been putting all the code in one single class instead of of spreiding...
0
417
by: 703designs | last post by:
I'm with FutureShock, both of you guys got a little too heated. But it livened up my midday a bit, for what it's worth. Thomas On Nov 10, 10:02 pm, FutureShock <futuresho...@att.netwrote:
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.