Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

PHP MYSQL INSERT Question

ok this is a long shot...

i am inserting a row into a table. the table has an auto-id field.

is there a way to get the auto-id assigned to this record from the insert. does the insert return anything other than true/false or are there any other functions i can run on the query to get the value that has been assigned.

i want to basically be able to get the value of the ID field without having to requery the database.
the information i am inserting could be the same but the id will always be different. so i could have multiple rows of data that looks the same but the id is different for each.



0
Fatlog
Asked:
Fatlog
  • 2
1 Solution
 
minichickenCommented:
you can use mysql_insert_id();

Example:

mysql_query ("insert into table values (....)"); //run your insert query first
$ID = mysql_insert_id(); //returns previous inserted ID from DB

j311y :)
0
 
FatlogAuthor Commented:
thanks

thats perfect

didnt think i would get an answer to this one!!
0
 
minichickenCommented:
Good stuff :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now