Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Returning Primary Key

    Hello,

    My mysql table is setup as the following:

    billingid (Primary Key, auto_increment)
    userid
    billingdate
    invoice

    I have a script that is inserting data into a mysql database table.
    PHP Code:
    mysql_query("INSERT INTO billing SET userid='$userid', billingdate='$billingdate', invoice='$invoice'"); 
    What I want to know is if there is a way to return the billingid value for the row that is inserted without querying the database for the record?

    For Example:
    PHP Code:
    mysql_query("INSERT INTO billing SET userid='$userid', billingdate='$billingdate', invoice='$invoice' RETURN billingid"); 

    Thanks
    jlimited
    Last edited by jlimited; 11-18-2006 at 11:31 PM. Reason: clarification

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    as long as you have `billingid` as an AUTO INCREMENT field, use mysql_insert_id()
    Last edited by boeing747fp; 11-18-2006 at 11:34 PM.


  •  

    Posting Permissions

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