Jump to content

Archived

This topic is now archived and is closed to further replies.

GingerRobot

auto_increment - finding value assigned*solved*

Recommended Posts

Ok, i am inserting a row into a mysql table and the field `id` is automatically given a number as it is set to auto-increment.

After performing the insert, is there any way to find out what number was actually put into the id field?

I hope that makes sense.

Thanks in advance.

Share this post


Link to post
Share on other sites
with mysql you can use the insert_id function, which can be found here - in the mysql documentation on php.net.

http://uk.php.net/manual/en/function.mysql-insert-id.php

If you have any trouble with it working, then I am sure others will be able to help - just beware that it will return the [i]last insert id[/i], so if you are running two inserts (info into two tables) it will return the id for the second table, NOT the first.

Share this post


Link to post
Share on other sites
You'll want to use a function called [url=http://uk.php.net/manual/en/function.mysql-insert-id.php]mysql_insert_id[/url]

Share this post


Link to post
Share on other sites
Thanks very much to both of you, that is exactly what i want.

Thanks again.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.