Jump to content

Inserts & Selects


yddib

Recommended Posts

$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?

Link to comment
Share on other sites

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

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.