insert a new row and get the id of inserted row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svsenthilkumar
    New Member
    • Dec 2007
    • 11

    insert a new row and get the id of inserted row

    Hai,

    i want to insert a record and retrieve id using php-mysql.

    i want insert a record by copy of another one table.
    after inserting i update a field in the inserted record.

    so, can i insert a record and return the inserted record id.
    (each record will insert by a unique id).


    regards,
    Senthil.V
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Read about mysql_insert_id

    Comment

    • svsenthilkumar
      New Member
      • Dec 2007
      • 11

      #3
      Originally posted by r035198x
      Read about mysql_insert_id

      Thanks for your reply.

      my problem is insert and get id for update a field.


      But mysql_insert_id give the previous insert id.

      (i think i will get an error when use mysql_insert_id )
      for example

      here i insert a query in a table "A" that will time a user can register a record( here insert the same table "A" by user it insert after fraction of second my insert query).

      now my 'mysql_insert_i d' read by system and i got the user insertion id.


      i think,
      it wil give prblem to my situation.


      plz. give some ideas


      regards,
      V.Senthil

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by svsenthilkumar
        Thanks for your reply.

        my problem is insert and get id for update a field.


        But mysql_insert_id give the previous insert id.

        (i think i will get an error when use mysql_insert_id )
        for example

        here i insert a query in a table "A" that will time a user can register a record( here insert the same table "A" by user it insert after fraction of second my insert query).

        now my 'mysql_insert_i d' read by system and i got the user insertion id.


        i think,
        it wil give prblem to my situation.


        plz. give some ideas


        regards,
        V.Senthil
        You won't get that problem if you store the last insert id into a variable just after inserting and then use the value of that variable in your next update.

        Comment

        Working...