[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!

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:

$qryinsert = "INSERT INTO pessoa VALUES (blablabla)";
sc_execsql($qryinsert);

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

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

[QUOTE=Giu;36456]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:

$qryinsert = "INSERT INTO pessoa VALUES (blablabla)";
sc_execsql($qryinsert);

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

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

[/QUOTE]

Works!

Thank you!!!

Great.

Close