Welcome to GraphicForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

[php+mysql] how to get the inserted record ID?

 
   Graphic Forums (Home) -> SQL Integration RSS
Next:  [php+mysql] passing data throught multiple pages?  
Author Message
sweetman

External


Since: May 30, 2006
Posts: 23



(Msg. 1) Posted: Wed May 21, 2008 7:29 am
Post subject: [php+mysql] how to get the inserted record ID?
Archived from groups: macromedia>dreamweaver (more info?)

Hi all,
I have a standard php page that inserts a record in a mysql db.

is there a way to save the record ID on a session variable just after
storing the new record on the db? I would like to be able to get this
record ID on a specific page where I would allow the user to print
this specific record, by filtering the db by this session variable.

I can use MX Kollection (last version, not PRO).

TIA

tony

 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
Michael Fesser

External


Since: Sep 15, 2005
Posts: 733



(Msg. 2) Posted: Wed May 21, 2008 7:29 am
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(sweetman)

> is there a way to save the record ID on a session variable just after
>storing the new record on the db? I would like to be able to get this
>record ID on a specific page where I would allow the user to print
>this specific record, by filtering the db by this session variable.

After inserting the record into the DB call mysql_insert_id() to get the
last auto-generated ID. Then you can store it in your session.

Micha

 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
sweetman

External


Since: May 30, 2006
Posts: 23



(Msg. 3) Posted: Wed May 21, 2008 7:29 am
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>After inserting the record into the DB call mysql_insert_id() to get the
>last auto-generated ID. Then you can store it in your session.
>Micha

Thanks

tony
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
Michael Fesser

External


Since: Sep 15, 2005
Posts: 733



(Msg. 4) Posted: Wed May 21, 2008 7:29 am
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(sweetman)

>>After inserting the record into the DB call mysql_insert_id() to get the
>>last auto-generated ID. Then you can store it in your session.
>>Micha
>
>Thanks

You're welcome.

Micha
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
sweetman

External


Since: May 30, 2006
Posts: 23



(Msg. 5) Posted: Wed May 21, 2008 3:58 pm
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>After inserting the record into the DB call mysql_insert_id() to get the
>last auto-generated ID. Then you can store it in your session.
>Micha

Ehmmm, Micha,

I can't get the value for mysql_insert_id().
I always get 0.

Where can I put it on my insert record form? (I'm using MX Kollection)

TIA again

tony
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
Michael Fesser

External


Since: Sep 15, 2005
Posts: 733



(Msg. 6) Posted: Wed May 21, 2008 4:25 pm
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(sweetman)

>>After inserting the record into the DB call mysql_insert_id() to get the
>>last auto-generated ID. Then you can store it in your session.
>>Micha
>
>Ehmmm, Micha,
>
>I can't get the value for mysql_insert_id().
>I always get 0.
>
>Where can I put it on my insert record form? (I'm using MX Kollection)

Have a look at the code. Insert it after the mysql_query() call, which
inserts the record, e.g.

....
mysql_query(...);
$_SESSION['lastId'] = mysql_insert_id();

HTH
Micha
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
sweetman

External


Since: May 30, 2006
Posts: 23



(Msg. 7) Posted: Wed May 21, 2008 5:30 pm
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>...
>mysql_query(...);
>$_SESSION['lastId'] = mysql_insert_id();
>HTH
>Micha

Hi Micha,
I think that it a bit more complicated.
I can't find any occurrence of that mysql call.

I used MX Kollection INSERT FORM function.

here is the code (partially):
===============================
<? // Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Make unified connection variable
$conn_test_conn = new KT_connection($tes_conn, $database_test_conn);

// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger

// Make an insert transaction instance
$ins_rl_test = new tNG_insert($conn_test_conn);
$tNGs->addTransaction($ins_rl_test);
// Register triggers
$ins_rl_test->registerTrigger("STARTER", "Trigger_Default_Starter", 1,
"POST", "KT_Insert1");
$ins_rl_test->registerTrigger("BEFORE",
"Trigger_Default_FormValidation", 10, $formValidation);
$ins_rl_test->registerTrigger("END", "Trigger_Default_Redirect", 99,
"2.php?idp1={id_rl}");
// Add columns
$ins_rl_test->setTable("rl_test");
$ins_rl_test->addColumn("nome_rl", "STRING_TYPE", "POST", "nome_rl");
$ins_rl_test->addColumn("cognome_rl", "STRING_TYPE", "POST",
"cognome_rl");
$ins_rl_test->addColumn("datanascita_rl", "DATE_TYPE", "POST",
"datanascita_rl");
$ins_rl_test->addColumn("cancellato_rl", "STRING_TYPE", "POST",
"cancellato_rl");
$ins_rl_test->addColumn("cancellato_data_rl", "DATE_TYPE", "POST",
"cancellato_data_rl");
$ins_rl_test->setPrimaryKey("id_rl", "NUMERIC_TYPE");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsrl_test = $tNGs->getRecordset("rl_test");
$row_rsrl_test = mysql_fetch_assoc($rsrl_test);
$totalRows_rsrl_test = mysql_num_rows($rsrl_test);
?>

===========================
as you can see, all data is processed by other functions in other
included files.... Sad.

I think I need to better understand the TNG engine and try to create a
little trigger that creates a session variable just after inserting
the record in the db.
I already tried to do so, honestly, but with really poor results.

Ciao Micha. Wink.

tony
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
Michael Fesser

External


Since: Sep 15, 2005
Posts: 733



(Msg. 8) Posted: Thu May 22, 2008 7:12 am
Post subject: Re: [php+mysql] how to get the inserted record ID? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(sweetman)

>I think that it a bit more complicated.
>I can't find any occurrence of that mysql call.
>
>I used MX Kollection INSERT FORM function.

OK. I'm not familiar with that one, but ...

>[...]
>// Execute all the registered transactions
>$tNGs->executeTransactions();
>
>// Get the transaction recordset
>$rsrl_test = $tNGs->getRecordset("rl_test");
>$row_rsrl_test = mysql_fetch_assoc($rsrl_test);
>$totalRows_rsrl_test = mysql_num_rows($rsrl_test);
>?>

.... I would try to insert the mysql_insert_id() at the end of this last
part.

Micha
 >> Stay informed about: [php+mysql] how to get the inserted record ID? 
Back to top
Login to vote
Display posts from previous:   
   Graphic Forums (Home) -> SQL Integration All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]