Skip navigation
lmaryott
Currently Being Moderated

Attach User Id to inserted records

Feb 22, 2012 3:57 PM

Tags: #php #dreamweaver #database #mysql

I'm building a page/form that will allow users to add new rows to my database.  I want to auto-populate the 'student_id' column in the table they are inserting into with the information contained in my table 'users' that contains their login information.  In both tables, their numeric id is 'student_id'. I have their username = their email.

 

How is this done?

 

to recap, i have them inserting rows into a table called sponsors.  I want the column sponsors.student_id to autopopulate with their student_id from the users table based on the fact that they are logged in as said user.

 

I know this must be possible, but I'm incredibly new to all of this.

 

Thanks in advance for any help!

 
Replies
  • Currently Being Moderated
    Feb 22, 2012 4:10 PM   in reply to lmaryott

    Typically when someone logs in you store their ID in a session variable. Are you storing the student_id or username in the session variable. If the former, then obviously you just need to use that in the insert statement.  If the latter, then you have 2 options.

     

    1. When retrieving their info at login, also capture the student_id. Then you can use the session variable directly in your insert statement
    2. Use a subselect in the insert statement that retrieves the student_id based on the username.
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points