Jump to content

[SOLVED] Retrieving PK from a Row Freshly Inserted


daniel244rock

Recommended Posts

Hello!

So I haven't had to post on PHPFreaks for Months and Months!! I must be improving, but obviously have a boatload yet to learn.  I have a script that copies a row from a database table into the same table, with all fields except the PK and a few others that are specific to the user entering the data.  The problem with this, is that the two rows (the one I copied from and the one newly created) are identical with the exception of the PK which is an auto-incrementing value. 

I need to be able to update a few columns with the user-specific data but don't know how to select the newly created row.  It seems that there should be a way you can find the PK when you do an INSERT statement.

For instance:

Tablename : table
PK : ID (Auto-increment)

----------------------------
|ID | name                       |
----------------------------
| 0 | Tommy                     |
----------------------------
| 1 | Timmy                      |
----------------------------
| 2 | James                      |
----------------------------

Then when you run "INSERT INTO table (name) VALUES (Jimmy)" have a way of getting the PK of 3.

If I'm confusing, then thats normal.  I'll try to answer any questions you guys have about my descriptions.
If its too much of  a dumb question, I'm not afraid to read some articles if you've got the links.
Thanks tons in advance. 

Daniel

Archived

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

×
×
  • 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.