Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    20

    Unanswered: Insert data into DB, return ID number

    I'm inserting an Article into a DB. The fields I'm inserting are Title, Intro, Content, Creation_Date. There is a field in the DB that is the primary key, Article_ID, which is auto-increment.

    I insert the article into the DB, and it is assigned the article_id by the DB. I want to use that ID later in my code on the same page. Is there any way to get SQL to return the ID on my Insert statement, or must I do a SELECT ... WHERE statement after I do my insert?

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by tlshaheen
    Is there any way to get SQL to return the ID on my Insert statement, or must I do a SELECT ... WHERE statement after I do my insert?
    There's a MySQL function called LAST_INSERT_ID()
    There is also a PHP function (if that's any use) called mysql_insert_id()

  3. #3
    Join Date
    Dec 2009
    Posts
    20
    The PHP function is perfect! Thank you very much for your response!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •