daniel244rock Posted December 14, 2006 Share Posted December 14, 2006 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 : tablePK : 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 Quote Link to comment https://forums.phpfreaks.com/topic/30575-solved-retrieving-pk-from-a-row-freshly-inserted/ Share on other sites More sharing options...
artacus Posted December 14, 2006 Share Posted December 14, 2006 after insert runs, $id = mysql_insert_id($db_conn); Quote Link to comment https://forums.phpfreaks.com/topic/30575-solved-retrieving-pk-from-a-row-freshly-inserted/#findComment-140825 Share on other sites More sharing options...
daniel244rock Posted December 14, 2006 Author Share Posted December 14, 2006 Oh Yes!! Flawlessly perfect function of goodness!! Thanks so much artacus, that was exactly what I was looking for.Daniel Quote Link to comment https://forums.phpfreaks.com/topic/30575-solved-retrieving-pk-from-a-row-freshly-inserted/#findComment-140847 Share on other sites More sharing options...
daniel244rock Posted December 14, 2006 Author Share Posted December 14, 2006 Oh yeah, and for anybody else who reads this that might need a bit more help, http://us3.php.net/mysql_insert_id should get you going, thanks again artacus Quote Link to comment https://forums.phpfreaks.com/topic/30575-solved-retrieving-pk-from-a-row-freshly-inserted/#findComment-140848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.