yddib Posted September 12, 2008 Share Posted September 12, 2008 $comment=$_POST['comment']; $linda='1'; mysql_query("SELECT f_name, l_name FROM gradinfo WHERE u_id = '$id'"); mysql_query("INSERT INTO comments (from_u_id,comment,u_id,f_name,l_name) VALUES ('$id', '$comment','$linda','f_name','l_name')"); We know this inserts f_name & l_name instead of the name linked with $id. How do I drag the 2 selected fields to be inserted in another table? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted September 12, 2008 Share Posted September 12, 2008 There are a couple ways, the first is to select the data into PHP values (which you are doing already), then use them in the insert. The other way is to use a INSERT...SELECT statement. But...before we go down those roads, I'm going to propose that you don't store the f_name,l_name in the comments table. You have the ID of the gradinfo table, so when you need to call the data, you can just do a JOIN: SELECT a.comment,b.f_name,b.l_name FROM comments a LEFT JOIN gradinfo b ON a.from_u_id = b.u_id Quote Link to comment 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.