follow user system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harman30
    New Member
    • Sep 2015
    • 19

    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
    Code:
      <div class="follow_box">
       <?php
        if(is_loggedin()){
         $id = $_SESSION['user_login'];
         $userid = $user;
         if($user !=$_SESSION['user_login']) {
         $follow_check="SELECT * from follow_user WHERE id_fk='$id' and user_id='$userid' ";
         $user_sql=mysql_query($follow_check);
         $count=mysql_num_rows($user_sql);
         if($count==0){
          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>";
          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>";
          }
          else{
          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>";
          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>";
          }
          }
          }
           else{
           echo "You must be logged in to view stuff and things";
          }
          ?>
    follow.js
    Code:
       $(function() {
       $(".follow").click(function(){
       var user_id = $(this).attr("id");
       var datastring = 'user_id='+ user_id ;
       $.ajax({
       type: "POST",
       url: "add_follow_user.php",
       data: datastring,
       success: function(html){}
       });
       $("#follow"+user_id).hide();
       $("#remove"+user_id).show();
       return false;
       });
       });
       $(function() {
       $(".remove").click(function(){
       var user_id = $(this).attr("id");
       var datastring = 'user_id='+ user_id ;
       $.ajax({
       type: "POST",
       url: "remove_follow_user.php",
       data: datastring,
       success: function(html){}
        });
       $("#remove"+user_id).hide();
       $("#follow"+user_id).show();
       return false;
       });
       });
       </div>
    add_follow_user .php

    Code:
    <?php
        include ( "./inc/header.inc.php" ); 
        if($_POST['user_id']){
        $user_id=$_POST['user_id'];
        $user_id = mysql_escape_String($user_id);
        $sql_in = "INSERT INTO follow_user(id_fk,user_id) VALUES ('$id','$user_id')";
        mysql_query( $sql_in);
        }
        ?>
    remove_follow_u ser.php

    Code:
    <?php
        include ( "./inc/header.inc.php" ); 
        if($_POST['user_id']){
        $user_id=$_POST['user_id'];
        $user_id = mysql_escape_String($user_id);
        $sql_in = mysql_query("DELETE FROM follow_user WHERE id_fk='$id' AND user_id='$user_id'");
        }
        ?>
Working...