Jump to content

[SOLVED] Retrieve ID of newly created record


stevesimo

Recommended Posts

Hi, I have created a form to add a new record to my table.  There is a field in the table however whose value will be generated using a given text string and the id number of the record.

 

For example suppose the ID of the record is 1030 then the string generated value will be something like

 

thisismystring1030

 

Does anyone know how I can retrieve the record ID as soon as I have created the record so that I can generate the value as mentioned above?

 

Just out of curiosity my next step after this is to create a session variable which willl store the record ID however I have never used these before.  Can anyone point me in the right direction? ;D:D 

 

Many thanks

 

Steve (Blackpool)

You may be able to:

 

INSERT INTO table (string) VALUES ( CONCAT('moo ', CAST( last_insert_id() as CHAR ) ) )

 

but I'm not sure if last_insert_id() will give you the correct answer... play around with it. Another idea may be:

 

INSERT INTO table (string) VALUES ( 'tmp' ); Update table SET string=CONCAT('moo ', CAST( last_insert_id() as CHAR ) );

 

NOTE this is two lines of SQL that run together.

 

monk.e.boy

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.