inserting data into another table event using a php variable..

I?m, having a problem inserting data into another table in an after insert event…

here is the code…

$insert_table = ‘inventarios’; // Table name
$insert_fields = array( // Field list, add as many as needed
‘codigo’ => “’$producto’”,
‘bodega’ => “’{codigo}’”,
‘existencia’ => “‘0’”,
);

$insert_sql = ‘INSERT INTO ’ . $insert_table
. ’ (’ . implode(’, ‘, array_keys($insert_fields)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields)) . ‘)’;

sc_exec_sql($insert_sql);

the problem is this code returns a blank value in the $producto variable like it shows in the sql generated bellow:

INSERT INTO inventarios (codigo, bodega, existencia) VALUES (’’, ‘56’, ‘0’)

since there is no value to be inserted in the codigo field if returns an error…

if i change the above code to this

$insert_table = ‘inventarios’; // Table name
$insert_fields = array( // Field list, add as many as needed
‘codigo’ => “’.$producto.’”,
‘bodega’ => “’{codigo}’”,
‘existencia’ => “‘0’”,
);

$insert_sql = ‘INSERT INTO ’ . $insert_table
. ’ (’ . implode(’, ‘, array_keys($insert_fields)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields)) . ‘)’;

sc_exec_sql($insert_sql);

now the value of the php variable appears but since i added the before and after dots it throws an error…

INSERT INTO inventarios (codigo, bodega, existencia) VALUES (’.MA0001.’, ‘59’, ‘0’)

what is wrong or what am i doing wrong?

‘codigo’ => $producto ?

EMC,

You might want to view the code that gets generated View->Source-> (the apl code).

I just did a copy and past of the example that did not work, and run it in a simple php file, and it worked fine.

Sometimes a scriptcase macro that looks like a function call, really isn’t and it gets exploded into different code where quotes can make a difference.

It could be the version of PHP you are running. Though implode and array_keys have been around a long time, so that it not likely.

I think you code is good. but i think that you test changes the variable $producto by a new field personalized.
{producto_code} = $producto;

i have a code in my form and it works fine, but it do not have variables php .

$insert_table = ‘pag_pgos’; // Table name
$insert_fields = array( // Field list, add as many as needed
‘PAG_CDGO’ => “0”,
‘NEG_CDGO’ => “[neg_cdgo]”,
‘SUC_CDGO’ => “{suc_cdgo}”,
‘TDO_CDGO’ => “’{tdo_cdgo}’”,
‘TER_CDGO’ => “{ter_cdgocli}”,
‘PAG_TERID’ => “’{ven_terid}’”,
‘PAG_FRMAPGO’ => “’{ven_frmapgo}’”,
‘NUM_MVMNTO’ => “{ven_cdgo}”,
‘PAG_FCHA’ => “now()”,
‘PAG_TTALPGAR’ => “0”,
‘PAG_VLORCNCLDO’ => “0”,
‘PAG_OBRVCION’ => “’.’”,
‘PAG_PROCSDO’ => “‘S’”,
‘PAG_FCHASSTMA’ => “now()”,
‘PAG_USRIO’ => “’[usr_login]’”,
‘PAG_ACTVO’ => “‘S’”
);

// Insert record
$insert_sql = ‘INSERT INTO ’ . $insert_table
. ’ (’ . implode(’, ‘, array_keys($insert_fields)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields)) . ‘)’;