Jump to content


Photo

How to use PHP to insert Primary Key into another table


  • Please log in to reply
1 reply to this topic

#1 lutzlutz896

lutzlutz896
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 October 2006 - 03:43 AM

I have been trying to figure this out, but can't seem to comprehend how it is done. I know how to use a form to insert data into a database table, and have that table create a unique ID (primary key). My problem is that once the user signs up and creates an account, there is another form in which they will fill out to list their products on the website. Of course the second form stores information into a different table. What I can't figure out is how to pass the primary key from one table, to another table, so that the two tables will be connected.

I know that the user can't possibly enter in the information, because they don't know what thier unique ID is since that is created by the database itself. I'm not sure how this is done, but I know that I need the unique ID from one table to be inserted into the other table so that it corresponds with the correct user. I have been looking through PHP books, but I can't find any information on how to do this. Any help would be much appreciated.

Thanks,

Jonathan

#2 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 03:56 AM

do a SELECT LAST_INSERT_ID();

Pass that ID to the next page via sessions or querystrings, then put it in a hidden in the new form.  It will post with the rest of the data.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users