This topic is locked

Save field in another table after add.

12/7/2006 10:35:09 AM
PHPRunner General questions
M
maxcolo author

Hi,

I have a chart you date composed by the followings fields:

table dati

id

name

last name

email

I would like that after the insertion the id and the last name are saved in a new chart that calls

Table prova

id

last name

is correctly this function:

function AfterEdit()

{

//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into prova (id,cognome) values ('$id',$cognome)";

db_exec($strSQLInsert,$conn);
}
hax0r 12/7/2006

Hi,

I have a chart you date composed by the followings fields:

table dati

id

name

last name

email

I would like that after the insertion the id and the last name are saved in a new chart that calls

Table prova

id

last name

is correctly this function:

function AfterEdit()

{

//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into prova (id,cognome) values ('$id',$cognome)";

db_exec($strSQLInsert,$conn);
}


first off, you're function is AfterEdit not AfterAdd. you might want to switch that. and as far as if it's correct or not, i dunno, is it working? I assume not since you posted.

M
maxcolo author 12/7/2006

Because this function don't work?

function AfterAdd()

{

//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into prova (nome, cognome) values ('$nome','$cognome')";

db_exec($strSQLInsert,$conn);
}



Best regards

Max

Sergey Kornilov admin 12/7/2006

Use BeforeAdd or BeforeEdit functions.
In those functions you can use $values["nome"], $values["cognome"] to access form values.

M
maxcolo author 12/7/2006

But if I use:

function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//********** Save new data in another table ************

global $conn,$strTableName;
$strSQLSave = "INSERT INTO prova (nome, cognome) values (";
$strSQLSave .= $values["nome"].",";

$strSQLSave .= $values["cognome"];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record

// return false in other case
}


Error
Errore di tipo 256

Errore di descrizione Unknown column 'zzzzzzz' in 'field list'

URL localhost/lavoro/curricula_add.php?

Errore di file C:\WM\www\lavoro\include\dbconnection.php

Errore di linea 26

Query SQL insert into `curricula`
Why?
Grazie mille

Max

M
maxcolo author 12/8/2006

Resolved....this

function BeforeAdd(&$values)

{

global $conn;

$strSQLInsert = "insert into prova (nome, cognome) values (".$values["nome"].",".$values["cognome"].")";

db_exec($strSQLInsert,$conn);

return true;

}

J
Jane 12/8/2006

Max,
did this error occur when you remove all events?
Also please check all field names and field type use in the event.

If field type is varchar use single quotes around $values:

$strSQLSave .="'". $values["cognome"]."'";

M
maxcolo author 12/8/2006

Max,

did this error occur when you remove all events?


no any error, when I remove all events?
New question

If I wanted to save in another chart after having added the record.
Table my_table

id

nome

cognome
which is the code to use in the function?

Alexey admin 12/11/2006

Max,
use Before record added event for this.

Add "Save new data in another table" action.

M
maxcolo author 12/11/2006

I ask excuse if they are a "testone". But I have need to understand the

things in order to learn them. You tanks for the patience and the

courtesy.

Max