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
    Regular Coder
    Join Date
    Jul 2009
    Posts
    186
    Thanks
    72
    Thanked 2 Times in 2 Posts

    How to get back the primary key of a new entry?

    In my SQL table, I have a primary key set up to auto-increment, called UserID. I add a row to the table by using the following code:

    Code:
    $sql = "INSERT INTO LUM_User (FirstName, LastName, VerificationKey, Email, Gender, DateJoined, IpJoined)	VALUES ('$FirstName','$LastName','$VerificationKey','$Email','$Gender','$DateJoined','$IpJoined')";
    
    if(!mysql_query($sql,$con)) {
      die('Fatal Error: ' . mysql_error());
    }
    How can I get back the value of the primary key of this new entry? This is probably a simple question but I am a novice PHP/SQL programmer. Thanks.
    Last edited by skcin7; 01-15-2010 at 03:09 AM.

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    skcin7 (01-15-2010)


  •  

    Posting Permissions

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