Max45 Posted April 11, 2020 Share Posted April 11, 2020 (edited) 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 April 11, 2020 by Max45 Quote Link to comment https://forums.phpfreaks.com/topic/310530-how-to-user-insert-select-with-my-two-tables-based-on-id/ Share on other sites More sharing options...
Barand Posted April 11, 2020 Share Posted April 11, 2020 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310530-how-to-user-insert-select-with-my-two-tables-based-on-id/#findComment-1576680 Share on other sites More sharing options...
Max45 Posted April 12, 2020 Author Share Posted April 12, 2020 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 Quote Link to comment https://forums.phpfreaks.com/topic/310530-how-to-user-insert-select-with-my-two-tables-based-on-id/#findComment-1576726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.