Jump to content

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.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.