SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grabbing value of last auto-incremented column

    I have a table containg the first, middle, and last names of article authors as well as an auto-incremented, primary key ID column. I have created a web form that allows me to enter these authors into a MySQL database. Once I enter an author's name into the database, I have the form show me the author's name I just added, but I also want to have the author's ID number display as well.

    I know this question has been asked many times, but I cannot seem to get the provided solutions to work. I have tried mysql_insert_id(), but the value returned is always 0:
    PHP Code:
    $addAuthor="insert into tblArticles_Authors set
    AuthorFirstName='
    $AuthorFirstName',
    AuthorMiddleName='
    $AuthorMiddleName',
    AuthorLastName='
    $AuthorLastName'";

    $getID=mysql_insert_id();
    echo 
    $getID
    When I go into the database and look, the author has been correctly added and the ID has been correctly incremented. However, the echoed ID number is always 0, no matter how big the ID number actually is.

    I have also tried to query the database:
    PHP Code:
    $addAuthor="insert into tblArticles_Authors set
    AuthorFirstName='
    $AuthorFirstName',
    AuthorMiddleName='
    $AuthorMiddleName',
    AuthorLastName='
    $AuthorLastName'";

    $query=mysql_query("select AuthorID from tblArticles_Authors where AuthorFirstName='$AuthorFirstName' and AuthorMiddleName='$AuthorMiddleName' and AuthorLastName='$AuthorLastName'" );
    echo 
    $query
    Again, everything is added to that database correctly, but the echo results in "Resource id#2" every time.

    I know this is a pretty simple problem, but as a newbie to all of this kind of stuff, I would greatly appreciate your help.

    Thanks,
    Auschten
    Last edited by auschten; Apr 16, 2003 at 20:48.

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind! I fixed it!


Bookmarks

Posting Permissions

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