[ic] return value of autonumber or code at time of INSERT

maillists lists at gmnet.net
Mon Aug 22 18:29:16 EDT 2005


On Mon, 2005-08-22 at 15:56 -0500, Mike Heins wrote:
> Quoting maillists (lists at gmnet.net):
> > On Mon, 2005-08-22 at 12:17 -0500, Mike Heins wrote:
> > > Quoting maillists (lists at gmnet.net):
> > > > HI,
> > > > 
> > > > I have searched the docs and mail list and I have not found the answer
> > > > to this. I need to be able to get the value of the primary key made by
> > > > autonumber or auto_increment at the time it is created.
> > > > 
> > > > Here is my scenario:
> > > > 
> > > > * user creates an account or logs in.
> > > > 
> > > > * user can insert a new record in a table via a form. call it tableA
> > > > 
> > > > * When the user inserts this record, into tableA, 2 things happen.
> > > > 
> > > >   1) user gets an email with the new record ID or code in the email. 
> > > >   2) I update the value of a field in another table say tableB with the
> > > > value of the ID or code from the new inserted record in tableA.
> > > > 
> > > > I know how to do all the inserts, email, and everything. I just can't
> > > > figure out how to return the value code of tableA at the time it is
> > > > created.
> > > > 
> > > 
> > > Depends how you are creating the record.
> > > 
> > > If it is with embedded Perl, it is returned from set_slice:
> > > 
> > > 	$Scratch->{new_key} = $db->set_slice(undef, \%record);
> > > 
> > > If it is with [table-editor] or mv_action=set, you should find [cgi
> > > the_key] set to the new key value upon return from writing. You can
> > > control where that value goes with mv_data_return_key, meaning if you
> > > do in the table-editor:
> > > 
> > > 	hidden.mv_data_return_key=foo
> > > 
> > > then [cgi foo] will contain the new key value.
> > > 
> > 
> > Thanks Mike,
> > 
> > I'm still not getting a value returned.
> > I hope this email is not too long...
> > 
> > I guess my problem is the "way" that I am inserting the data.
> > My form is based on the "contact us" web form in the foundation catalog,
> > where is sends an email.  My database "tableA" is a mysql table with
> > code set to type=INT(20) and auto_increment. 
> 
> If you are using [query ...], which was not intended by me to do database
> updates, then all bets are off. I don't know how to get the key off the top
> of my head and I ain't looking.
> 
> I suggest you replace it with an embedded Perl call that does the same thing,
> and get it back from $db->set_slice(). There are lots of examples in the
> admin pages and elsewhere if you search for set_slice.


Thanks again Mike,

Sorry for the confusion. I will keep it short.  I am not using query to
set this data. the query is only used to update another table later on.
I am inserting a NEW record.

This is the way I am inserting the new record with a form:
I was once told that I need to set the value of "code" to NULL on the
form in order for MySQL to create the new record. MySQL is doing all the
auto_increment work.  It seems that MySQL is not telling IC what the new
code is.

<INPUT TYPE=HIDDEN NAME="mv_data_table"    VALUE="tablename">
<INPUT TYPE=HIDDEN NAME="mv_data_key"      VALUE="code">
<INPUT TYPE=HIDDEN NAME="mv_data_fields" VALUE="code">
<INPUT TYPE=hidden NAME=mv_todo     VALUE=set>
<INPUT TYPE=hidden NAME=code VALUE="NULL">
<INPUT TYPE=SUBMIT name=mv_check VALUE="[L]Send Request[/L]">
[set Send Request]
  [set mv_data_enable]1[/set]
  [set mv_data_function]insert[/set]
[/set]

I tried adding this in my form:
<INPUT TYPE=hidden NAME=mv_data_return_key VALUE="return_code">

I also tried this:
[set Send Request]
  [set mv_data_enable]1[/set]
  [set mv_data_function]insert[/set]
  [set mv_data_return_key]return_code[/set]
[/set]

Then in the success page I need the value of the "code" field of the new
created record so I put [cgi return_code]

So far nothing works. Should I do this a totally different way?

Thanks again for your help.
Chris




More information about the interchange-users mailing list