returning autogenerated ID on new item

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toodi4

    returning autogenerated ID on new item

    Lets say you have a form that when saved to the mysql database creates
    a unique incremental id. The form is just the first part of a series
    of things the user can do, so once the ID is created, the page would
    need to know immediately what this ID is. Is there a way to grab this
    ID instantly once it is created? Obviously if this were a sign-up for
    and a new user name and password are involved, you can have the user
    login after the initial set up and this select statement would bring
    back the ID. But the situation I have doesn't work like that.

    The way I have been dealing with this is simply to have a select
    statement after the initial insert that requests the record based on a
    couple of other fields that are likely unique. But this seems like a
    rather kludgy way of doing it. Is there some other solution.

  • Andy Hassall

    #2
    Re: returning autogenerated ID on new item

    On 5 Jan 2007 14:25:01 -0800, "toodi4" <toodi4@hotmail .comwrote:
    >Lets say you have a form that when saved to the mysql database creates
    >a unique incremental id.
    So, you have an auto_increment primary key?
    >The form is just the first part of a series
    >of things the user can do, so once the ID is created, the page would
    >need to know immediately what this ID is. Is there a way to grab this
    >ID instantly once it is created?
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Hendri Kurniawan

      #3
      Re: returning autogenerated ID on new item

      mysql_insert_id ()
      See the manual for any pitfalls

      Hendri Kurniawan

      toodi4 wrote:
      Lets say you have a form that when saved to the mysql database creates
      a unique incremental id. The form is just the first part of a series
      of things the user can do, so once the ID is created, the page would
      need to know immediately what this ID is. Is there a way to grab this
      ID instantly once it is created? Obviously if this were a sign-up for
      and a new user name and password are involved, you can have the user
      login after the initial set up and this select statement would bring
      back the ID. But the situation I have doesn't work like that.
      >
      The way I have been dealing with this is simply to have a select
      statement after the initial insert that requests the record based on a
      couple of other fields that are likely unique. But this seems like a
      rather kludgy way of doing it. Is there some other solution.
      >

      Comment

      Working...