Possible Duplicate:
PHP: how to get last inserted ID of a table?
I am having a problem with my MySQL insert. I have an Id column that is AUTO_INCREMENT and I run this code into that table:
mysql_query("INSERT INTO tickets (Submitted, UNIXtime, Subject, Text, User, Priority, Status, Service) VALUES ('$date', '$UNIXtime', '$subject', '$text', '$userss', '$priority', '$status', '$service')");
It then inserts an Id number in that row. How would I get that ID number so I can echo it out for example $id = (The ID number from that submit);?
echo $id;
Thanks for the help. If you could, can you rewrite the code to make it work and post it so I know what to do?
You’re looking for
mysql_insert_id(). This function will return the ID of the last query.You could call it after running your query: