473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

follow user system

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_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 = mysql_query("DELETE FROM follow_user WHERE id_fk='$id' AND user_id='$user_id'");
  7.     }
  8.     ?>
Sep 20 '15 #1
0 1216

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

Similar topics

3
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...
0
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...
45
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...
1
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...
2
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
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...
0
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.