Insert a record on another table

Hi,

hope someone can assist me. I want to insert a record into another table via the OnAfterUpdate event on a form. When I use the example code given in Scriptcase as below, it works fine as it inserts the word ‘test’ in the other table, but I want to assign the value that already exists in the a field in the form to be inserted into the other table (which can change every time you update the form). Something like $projectadd = {project_request} and then use $projectadd as the value to be inserted into the projects table for the project_name field instead of ‘test’, but this comes back with an error once I run the app and click save. I’m sure I’m just assigning the variable wrong.

$insert_table = ‘projects’;
$insert_fields = array(
‘project_name’ => “‘test’”,
);

Any suggestion would be appreciated

Hi, try with this

$insert_table = ‘projects’;
$insert_fields = array(
‘project_name’ => “’” . {project_request} . “’”,
);

sc_exec_sql(“INSERT INTO $insert_table (project_name) VALUES (” . $insert_fields[‘project_name’] . “)”);

Other option:
$projectadd = sc_sql_injection({project_request});

$insert_sql = “INSERT INTO projects (project_name) VALUES ($projectadd)”;

sc_exec_sql($insert_sql);

1 Like
sc_begin_trans();
$error = 0;

$sql = "INSERT INTO ......";
sc_select(response, $sql);
if ({response} === false){
	$msg_error = {response_erro};
    $error = 1;
}

if(!$error){
    sc_commit_trans();
}else{
    sc_rollback_trans();
	echo "Error: ".$msg_error;
}

Thanks this option worked for me