Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1082467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:18:10+00:00 2026-05-16T22:18:10+00:00

$(function() { $(.follow).click(function(){ var element = $(this); var I = element.attr(id); var info =

  • 0
$(function() {
      $(".follow").click(function(){
        var element = $(this);
        var I = element.attr("id");
        var info = 'id=' + I;

        $.ajax({
            type: "POST",
            url: "listen.php",
            data: info,
            success: function(){}
            });

        $("#follow"+I).hide();  ///showing the remove button after the data has been entered
        $("#remove"+I).show();
        return false;

      });
});

The PHP file listen.php

<?php session_start();
include_once ('includes/connect.php');

$id = $_POST['id'];
$follower = $_SESSION['user_id'];

 $registerlistener = mysql_query("INSERT INTO relationships (leader, listener) VALUES('".$id."', '".$follower."')");
?>

what I want to do is when I click the follow button, I want to check if the data has been entered into the database, before showing the remove button, basically checking on the background.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:18:11+00:00Added an answer on May 16, 2026 at 10:18 pm

    mysql_query will return TRUE or FALSE. You can echo that from the PHP script, and have the ajax call read it.

    listen.php:

    <?php session_start();
    include_once ('includes/connect.php');
    
    $id = $_POST['id'];
    $follower = $_SESSION['user_id'];
    
     $registerlistener = mysql_query("INSERT INTO relationships (leader, listener) VALUES('".$id."', '".$follower."')");
    
    echo json_encode(array('response'=>$registerlistener));
    ?>
    

    In your JavaScript:

    $.ajax({
    type: "POST",
    url: "listen.php",
    data: info,
    dataType: 'json',
    success: function(data){
        if(data.response){
            // mysql_query returned TRUE
            $("#follow"+I).hide();
            $("#remove"+I).show();
        }
        else{
            // FALSE
        }
    }
    });
    

    If you want, you can use the $.post shorthand:

    $.post('listen.php', info, function(data){
        if(data.response){
            // mysql_query returned TRUE
            $("#follow"+I).hide();
            $("#remove"+I).show();
        }
        else{
            // FALSE
        }
    }, 'json');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, in my code I have for example, this: $('.follow').click(function(){ var myself = $(this);
Script is as follows; $(#Results a).live('dblclick', function(event){ var src = $(this).attr(href); if (event.type ===
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
I have asked and done the follow code: $(document).ready(function() { $('.gallery').each(function(index, element) { var
I've got follow source code: <html> <head><script type=text/javascript> function test() { var links =
I have the following JQuery code: jQuery(function($) { $j(.follow_btn) .click( function() { var element
My code is as follows: <script> var i = 2; $(document).ready(function(){ $(#newrow).click(function(){ $(#maintable).append('<tr> <td><input
my curl function cannot follow the redirection of Facebook external link redirector, l.php and
I created a javascript class as follow: var MyClass = (function() { function myprivate(param)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.