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

  • Home
  • SEARCH
  • 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 8600845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:42:26+00:00 2026-06-12T01:42:26+00:00

i am creating a social site using PHP and HTML. i want to add

  • 0

i am creating a social site using PHP and HTML. i want to add “ADD FRIEND” button or link on my site. I wonder how can i do that. means whenever user searches for some name, then related search get displayed sequentially.

What i want is add friend button in front of every user that listed by search.. is there any way i can do that?

so if user click on that button then user id and friend id get inserted into friend table?

Thanks in Advance.

  • 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-06-12T01:42:28+00:00Added an answer on June 12, 2026 at 1:42 am

    Ok, I’ve done this, first of all set a session variable and store current logged in user id in that like this

    $_SESSION['user_id'] = //loggedin user id
    

    now I am not aware what kind of database design are you using, or what because you’ve not specified or provided any code from your side but simple way you can do this is make a simple submit button encapsulate it within a form tags, and use post method

    <?php
    if(isset($_POST['add_friend'])) {
    $current_user = $_SESSION['user_id']; //This will fetch user id of the person who is logged in and for this you need to have a user id in your session for the user who logs in
    
    $friendid = $_POST['friend_id']; //This will assign friend id to variable $friendid
    
    //Now execute the insert statement
    if(mysqli_query($connect, "INSERT INTO addfriendtable(user_id, friend_id) VALUES('$current_user','$friendid')")) {
    echo 'success';
    } else {
    echo 'Error Occured';
    }
    }
    
    $fetch_records = mysqli_fetch_array($connect, "SELECT name, userid FROM table");
    while ($show_users = mysqli_fetch_array($fetch_records)) {
    //loop all search results
    //place this code in front of all results
    ?>
    <form method="post">
    <input type="hidden" value="<?php echo $show_users['user_id']; ?>" name="friend_id">
    <input type="submit" name="add_friend" value="Add Friend" />
    </form>
    <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a social site for teachers (non-programmers) on which teachers can add events,
I am creating a social site and for search want to try solr or
I'm creating a social networking site with features similar to Facebook. I want to
Im currently creating a PHP application that searched various Social Media and analyses the
I am creating a simple design for a social-networking site using the MVC paradigm(in
I'm creating a little social network in Rails, where people can add eachother as
I'm one man shop, creating a social site. If my site becomes popular, will
I am creating a social tool - I want to allow search engines to
I'm currently developing a large site that handles user registrations. A social networking website
I am creating a Django app and want to have visualizations of a social

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.