Jump to content

get inserted id(auto) from insert statement


shocker-z

Recommended Posts

Hi there fella's and lasses..

im running this code
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
$count_add_q=mysql_query("INSERT INTO countdowns (username, date, subject, description, txtcolor, bgcolor) VALUES('$session_username','$count_date','$count_subject','$count_description','$count_txtcolor','$count_bgcolor')");
[/quote]

Just wondered if there is a way that from that insert statement i can also grab the ID that is added auto.. Recently i have basicaly done a select statement to select all the exact data that has been inserted but i feel that there must be an easier way??

Regards
Liam (stuck at work while sun is out and blue skys (peeping thru the small window at end of tech callcentre :( ))


**yes that was a vote for sympathy [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] **
Link to comment
https://forums.phpfreaks.com/topic/9535-get-inserted-idauto-from-insert-statement/
Share on other sites

I believed you are look for [a href=\"http://uk.php.net/manual/en/function.mysql-insert-id.php\" target=\"_blank\"]mysql_insert_id[/a]

This funtions returns the the previous auto_incremented row. Click the link above for more information on the function.
agree with ober. MAX(ID) might not always be the one you've just inserted for that particular connection. if you prefer sql, try
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] LAST_[span style=\'color:blue;font-weight:bold\']INSERT[/span]_ID() [color=green]FROM[/color] [color=orange]table[/color] [!--sql2--][/div][!--sql3--]

Archived

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

×
×
  • 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.