Jump to content

How to user insert... select... with my two tables based on id?


Max45

Recommended Posts

How to user insert... select... with my two tables based on id?
Hi all,
I have two tables
Table1_Name= users ->Which has all users
Tabel2_Name=addfriend -> which I to want add users to it from table1(users) based on their id
Here my code that didn't work

$id = $_GET['id'];
  $sql = "INSERT INTO addfriend(fname)
SELECT fname,  
FROM users WHERE id = $id"; 


   

Edited by Max45
Link to comment
Share on other sites

Table "addfriend" should contain (userid, friendid) only - no name. Don't bother. Problem solved.

Also, having a row with just a name will not tell you whose friend it is.

For future reference, "didn't work" tells us absolutely nothing about your problem.

And just posting a query that "doesn't work" only tells us what you don't want to do, not what you are trying to do.

  • Like 1
Link to comment
Share on other sites

19 hours ago, Barand said:

Table "addfriend" should contain (userid, friendid) only - no name. Don't bother. Problem solved.

Also, having a row with just a name will not tell you whose friend it is.

For future reference, "didn't work" tells us absolutely nothing about your problem.

And just posting a query that "doesn't work" only tells us what you don't want to do, not what you are trying to do.

Thanks a lot buddy.

And sorry if my post is not understandable.

See ya

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.