Announcement

Collapse
No announcement yet.

[SOLVED]Insert in Another Table Before Insert in Principal Table

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED]Insert in Another Table Before Insert in Principal Table

    Hi!

    I have two tables:

    1) Pessoa:
    id int,
    nome varchar(50),
    ativo tinyint(1)

    2) Pessoa_Fisica:
    id int,
    pessoa_id int,
    cpf int(11),
    sexo tinyint(1),
    data_nascimento date,
    nome_mae varchar(50),
    nome_pai varchar(50)

    In Pessoa_Fisica registration form, contains all the fields mentioned above.

    I must first enter the data of the Pessoa table, and then return the id of Pessoa, and then enter the data in Pessoa_Fisica.

    I wonder what is the best way to perform this operation.

    I've tried to do using the onBeforeInsert event to enter the Pessoa data, which could enter the data in that table, but the data Pessoa_Fisica table does not insert.
    The strange thing is that the application does not give any error, not simply inserts the data Pessoa_Fisica table.

    Someone would have any suggestions?


    Thank you!
    Last edited by diogoaltoe; 05-10-2015, 10:39 PM.

  • #2
    You have to do a manual INSERT statement on pessoa_fisica, then retrieve ID (on MySQL you can use LAST_INSERTID function), and then equals the field.

    PSEUDOCODE:
    PHP Code:
    $qryinsert "INSERT INTO pessoa VALUES (blablabla)";
    sc_execsql($qryinsert);

    $qrylastID"SELECT last_insert_id()";
    sc_lookup(pessoaID$qrylastID);

    {
    pessoa_id} = {pessoaID[0][0]}; 
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      Originally posted by Giu View Post
      You have to do a manual INSERT statement on pessoa_fisica, then retrieve ID (on MySQL you can use LAST_INSERTID function), and then equals the field.

      PSEUDOCODE:
      PHP Code:
      $qryinsert "INSERT INTO pessoa VALUES (blablabla)";
      sc_execsql($qryinsert);

      $qrylastID"SELECT last_insert_id()";
      sc_lookup(pessoaID$qrylastID);

      {
      pessoa_id} = {pessoaID[0][0]}; 

      Works!

      Thank you!!!

      Comment


      • #4
        Great.

        Close
        /Giuseppe

        Professional Scriptcase Services
        Some Customers opinions

        Comment

        Working...
        X