> -----Original Message-----
> From: Mariusz [mailto:[EMAIL PROTECTED]] 
> Sent: 09 September 2002 05:59
> To: perl
> Subject: perl and my DB...
> 

> (Can I submit the record via DBI and read the primary key 
> "ID" within the same script. Other words, can I send the last 
> name creating a new record, and then ask "what ID did you 
> just create?". Then I could use that for the rest of my pages 
> and keep adding data into the same record by using the unique ID. 

The answer is: depends on your database - most let you know the last
inserted ID - for example in MySQL this is available as

  my $insertid = undef;
  my $result = $dbh->executeSQL(%sql);
  if ( $result+0  ) {
    $insertid = $dbh->{mysql_insertid};
  }
  if ( defined $insertid ) {
    ...
  }

perldoc DBD::mysql and / for insertid

Note that this is dependant upon your table being set up with a DB
generated identity column.

You can then put the id into a hidden field on the subsequent forms to
carry the data forward. Might also pay to add other data so that you
don't end up updating the wrong record - you should probably also carry
forward your lastname field, so that your update looks like:

UPDATE mytable SET firstname=? 
  WHERE myId=? and lastname=?

Regards
Jeff


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to