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 3278554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:29:39+00:00 2026-05-17T19:29:39+00:00

I’m trying to make a little project for adding friends. When you click the

  • 0

I’m trying to make a little project for adding friends.
When you click the add friend button you are sending an Ajax call with the friend id & username (they are the id and name attributes of each add button) to the add.php file.
(The mysql structure is: 1 users table + X tables named the user’s name(columns: friendid, ispending))
In the PHP file there are only 2 MySQLi queries: Here is the code for the add file:

session_start();
$friendid = $_POST['id'];
$myname = $_SESSION['username'];
$friendname = $_POST['name'];
$myid = $_SESSION['id'];
$add = new Mysqlconnect();
$add->db->query("INSERT INTO $myname VALUES($friendid, 'yes')");
$add->db->query("INSERT INTO $friendname VALUES ($myid, 'yes')");
$add->db_Close();

The Mysqlconnect class is required i just didn’t want the code here to be too long.
Here’s the Ajax call:

$('.add').click(function(){
 var name = $(this).attr("name");
 var id = $(this).attr("id");
   $.ajax({
      type: "POST",
      data: "&name="+name+"&id="+id,
      url: 'add.php',
      success: function(){
         alert("success");
      }
   });
});

THE PROBLEM :
When I click “add friend” it does alert “success” but only one table gets updated everytime or even no table at all.
Though one time I clicked it and it did work (I did not change the code that time, I tried clicking like every 20 seconds).

How can I solve this?

  • 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-17T19:29:39+00:00Added an answer on May 17, 2026 at 7:29 pm

    if i understood you correctly you seem to be creating a new table for each user’s friends (1 users table + X tables named the user’s name) this isnt a good approach and you’d be better off with just 2 tables: users and user_friends as follows:

    drop table if exists users;
    create table users
    (
    user_id int unsigned not null auto_increment primary key,
    username varbinary(32) unique not null
    )
    engine=innodb;
    
    drop table if exists user_friends;
    create table user_friends
    (
    user_id int unsigned not null,
    friend_user_id int unsigned not null,
    created_date datetime not null,
    primary key (user_id, friend_user_id) -- note clustered composite PK (innodb only)
    )
    engine=innodb;
    

    A full example script can be found here : http://pastie.org/1242699

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.