473,609 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing follow to unfollow on click

19 New Member
I am trying a create a follow system, with this code but the follow button doesn't change to unfollow on click. I manually tried inserting values in database through phpmyadmin (so that one user now follows another). I should now see Unfollow but still shows as Follow. My db connection is in header file so I am using include header file.

Code on profile.php
Expand|Select|Wrap|Line Numbers
  1.    <?php include ( "./inc/header.inc.php" ); ?>
  2.  
  3.      <?php
  4.        function is_loggedin()
  5.      {
  6.      return (!empty($_SESSION['user_login']));
  7.      }
  8.     function is_profile($user = false)
  9.      {
  10.      if(!$user)
  11.         return false;
  12.  
  13.       return (is_loggedin() && ($_SESSION['user_login'] == $user));
  14.       } 
  15.    // If no user requested just assign false
  16.      $user   =   (!empty($_GET['u']) && ctype_alnum($_GET['u']))? $_GET['u'] : false;
  17.     // If the user is valid (not empty)
  18.  
  19.     if($user != false) {
  20.  
  21.     $username   =   mysql_real_escape_string($user);
  22.     //check user exists
  23.     $check      =   mysql_query("SELECT username, first_name FROM users WHERE username='$username'");
  24.  
  25.     if (mysql_num_rows($check) === 1) {
  26.             $get        =   mysql_fetch_assoc($check);
  27.             $username   =   $get['username'];
  28.             $firstname  =   $get['first_name'];  
  29.         }
  30.     else {
  31.             echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/tutorials/index.php\">"; 
  32.             exit;
  33.         }
  34.         }
  35.  
  36.       $my_id = $_SESSION['user_login'];
  37.       $u_id = $user;
  38.       ?>
  39.  
  40.      <?php
  41.      if($u_id !=$_SESSION['user_login']) {
  42.      $check = mysql_query("SELECT id FROM follow WHERE user_one='$my_id' AND user_two='$u_id'");
  43.      if(mysql_num_rows($check) == 1){
  44.       echo "<a href='actions.php?action=Unfollow&u_id=$u_id'>Unfollow</a>";
  45.        }
  46.       else{
  47.        echo "<a href='actions.php?action=Follow&u_id=$u_id'>Follow</a>";
  48.        }
  49.       }
  50.      ?>
  51.  
Code for actions.php
Expand|Select|Wrap|Line Numbers
  1.  
  2.    <?php include ( "./inc/header.inc.php" ); 
  3.  
  4.    $my_id = $_SESSION['user_login'];
  5.      $u_id = $user;
  6.     ?>
  7.  
  8.    <?php
  9.    $action = $_Get['action'];
  10.    $u_id = $_GET['u_id'];
  11.  
  12.     if($action == 'Follow'){
  13.    mysql_query("INSERT INTO follow VALUES ('','$my_id','$u_id')");
  14.     }
  15.       if($action == 'Unfollow'){
  16.          mysql_query("DELETE FROM follow WHERE user_one='$my_id' AND  user_two='$u_id'");
  17.     }
  18.    header('Location: profile.php?u='.$u_id);
  19.    ?>
Sep 18 '15 #1
0 1137

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

Similar topics

2
11033
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
13
1853
by: mike | last post by:
I have some elements that I want to change color when I mouse over them and them back on mouse off. I'd like the color to remain with "#c7d0e0" when the user clicks on them. <td style="cursor:hand;" onMouseOver="this.style.background='#c7d0e0';" onMouseOut="this.style.background='#ffffff';" onClick="chg_the_color();">
4
4016
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code ontop of the webform1: Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code "
3
4929
by: Janelle.Dunlap | last post by:
I have an Excel spreadsheet containing a column of hyperlinks that I need to import into Access. I have no trouble importing (in my case actually linking) the spreadhsheet to the Access table, however the column of hyperlinks lose their URL's in transit and no longer are active links. To try and fix the problem I am using this bit of code in my Excel spreadsheet to copy the URL of each hyperlink into a new column that can then be...
4
1307
by: browser newbie | last post by:
Hello How can I capture the link a user clicks on ? After capturing will I be able to form the HTTP request so that I can change the server its going to? For example...if the URI in the page says www.link1.com/data1, should the user click on it, I would like this to be send to server1.link1.com to get the url /data1
4
5050
by: RLN | last post by:
I have a form that does not display correctly. frm1 opens frm2 via a command button. My three problems with frm2: 1. Displays in form view when called from the button. (should be datasheet view) 2. "Shortcut Menu" is set to "Yes", however I cannot right click in the form to go to design view. These properties are already set on frm2:
3
6199
by: Andrew Jocelyn | last post by:
Hi I have couple of dropdown controls each with a requiredfieldvalidator. I clear the dropdownlist in the button click event. When the page is rendered the dropdown validator already flags it's error message. I checked the IsValid property in the prerender event and it says it's false. protected void Button_Click(object sender, EventArgs e) { ddl.ClearSelection();
0
1227
by: harman30 | last post by:
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 ...
1
6822
KeredDrahcir
by: KeredDrahcir | last post by:
I'm using a nested list as a menu with sub menu items. I used to do it where if you hovered over main menu item, the sub menu items would appear by changing the display from none to block. I decided to make the sub menus looks as if they were dropping down and used CSS transitions. The problem I have is that in the first approach if you touched a main menu item on an iPad the sub menu would display and you would touch it again to follow the...
0
8115
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8557
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8513
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5504
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4007
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1638
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1374
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.