Pulling correct PK

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
comtek
Forum Commoner
Posts: 39
Joined: Tue Feb 17, 2004 10:46 pm

Pulling correct PK

Post by comtek »

I am working on a DB that will contain 3 tables

1. patients
2. house_members
3. documents

Tables 2 and 3 will have a FK from table 1

I have an initial form which inputs data into table 1. After data is entered into table it is displayed on the screen along with a secondary form. The information in this form is to be input into table 2. Upon submitting this form, the info is displyed again with another form to upload files into table 3.

The 2nd and 3rd forms are dynamic and depend on the info from the previous form.

My question is... How do I pull the correct PK from table 1 so that it can be entered as the FK in tables 2 and 3?

Its not too much of a problem if only one person is entering applications, but what if more than one are submitting to the db?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

don't know the dbms you are using, but if you are using MySQL which has autoincrement, you could select last_insert_id to get the last generated id and store that in a session... (other dbms usually have something similar)
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

Post by voltrader »

What you could do is pass the FK from the first page as a hidden HTML POST variable;

if you're worried about security, you can encrypt it, then decrypt it -- that's what I do at least.

Somthing like <input type='hidden' name='fk_var' value='$fk_var'>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i would suggest sessions for variables that need to be available on multiple pages... (not only safer but also doesn't require all those values to be transported between client and server...)
Post Reply