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.



FatlogAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
minichickenConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.