I don’t get how your code is supposed to add or change anything in any table: where is the insert or update SQL statement?
You just declare two variables ($insert_table and $insert_fields) but you do nothing with them.
This is the code snippet generated by SC for “[SIZE=12px]Insert a record on another table”[/SIZE].
As you can see, once the variables are declared, they are used to create the $insert_sql statement variable that it is then executed via the sc_exec_sql() macro.
/**
* Insert a record on another table
*/
// SQL statement parameters
$insert_table = 'my_table'; // Table name
$insert_fields = array( // Field list, add as many as needed
'field_1' => "'new_value_field_1'",
'field_2' => "'new_value_field_2'",
);
// Insert record
$insert_sql = 'INSERT INTO ' . $insert_table
. ' (' . implode(', ', array_keys($insert_fields)) . ')'
. ' VALUES (' . implode(', ', array_values($insert_fields)) . ')';
sc_exec_sql($insert_sql);
But since you are using the code in the onChange event maybe you need the snippet for “[SIZE=12px]Update another table”[/SIZE]?
I’m not sure I understand what you are trying to do (and how)…
/**
* Update a record on another table
*/
// SQL statement parameters
$update_table = 'my_table'; // Table name
$update_where = "field_3 = 'condition'"; // Where clause
$update_fields = array( // Field list, add as many as needed
"field_1 = 'new_value_field_1'",
"field_2 = 'new_value_field_2'",
);
// Update record
$update_sql = 'UPDATE ' . $update_table
. ' SET ' . implode(', ', $update_fields)
. ' WHERE ' . $update_where;
sc_exec_sql($update_sql);