Jump to content

Archived

This topic is now archived and is closed to further replies.

kenquad

Form variables, server variables, confusion and problems....

Recommended Posts

Hi all:

I'm new to the forum and also new to PHP.  Please bear with me if this is the dumbest question ever.  I am writing a modest corporate database application via Dreamweaver to keep track of units in inventory.  I've configured the testing server (LAMP) and set up an entry page to where items can be added to the database through the web browser.  Now some items have one or more associated items (options or accessories) which are in a separate table.  I want to link the two tables with what I understand to be the classic RDBMS method: a common key.  This common key is furnished in the "unit_id" column of my "units_main" table, where a unique, auto-generated integer is assigned to each item.  The same column exists in my "di_options" table, only not as the primary key, so duplicate entries may be made. 

Sorry if this is getting long-winded.

Now after entering the primary data for the unit, I want to proceed immediately to a screen where I can add records for accessories to the "di_options" database, linked to the unit I just created by the unit id.  Now this would not be a problem if this unit id were user-generated.  The user could simply enter the unit id of the unit he just created by hand from memory (awkward, of course, but doable).  However, since the unit id is auto-generated (there isn't even a box on my form to enter it), the user has no way of knowing it without backing up to the inquiry screen and looking it up!  I know there must be a way to carry over the auto-generated user id from the record into the form on the accessory entry page.  I have tried to do this using variables... but as I tried to write down my logic for that just now, it fell apart.

So, does anyone know how to carry over an auto-generated key from a record just created into a form?

If so, thanks.

Ken Quad

Share this post


Link to post
Share on other sites
Never mind, I found the solution.  Simple as pie, for anyone else who's encountered this: one just sets a string, say, $last_value to mysql_insert_id() and then echoes the string!

Share this post


Link to post
Share on other sites

×

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.