Insert On Form with Apostrophe Error

I have a form that adds a note into a client record. This is a Multiline text field. If the data entered into the system has an apostrophe in it this errors out due to the apostrophe not being read as a string.

I have another project with a similar form that works fine. I compared the setup of both projects and they use the same dev environment. I cannot see why this work in one form/project and not another.

Note this only happens when a record is inserted. Updating works fine.
[TABLE=“align: center, cellpadding: 2, cellspacing: 0”]
[TR=“bgcolor: #ffffff”]
[TD][/TD]
[TD=“align: left”]PHP: 7.0.15[/TD]
[/TR]
[TR=“bgcolor: #f5f6f8”]
[TD] [/TD]
[TD=“align: left”] [/TD]
[/TR]
[TR=“bgcolor: #ffffff”]
[TD][/TD]
[TD=“align: left”]WEB Server: Apache/2.4.25 (Unix) mod_fcgid/2.3.9[/TD]
[/TR]
[TR=“bgcolor: #ffffff”]
[TD] [/TD]
[TD=“align: left”]ScriptCase Devel: 9.4.024[/TD]
[/TR]
[TR=“bgcolor: #f5f6f8”]
[TD] [/TD]
[TD=“align: left”]ScriptCase Build: 10[/TD]
[/TR]
[TR=“bgcolor: #ffffff”]
[TD] [/TD]
[TD=“align: left”]ScriptCase Prod: 9.4.024[/TD]
[/TR]
[/TABLE]

Try doing a trim(addslashes({fieldname})) when it gets validated. See if that gets rid of the issue.

I did find out the issue is in a custom button I created using the following code. {csmr_note_info} is the field that contains all of the user entered notes which can contain special characters
any further suggestions?

// SQL statement parameters
$insert_table2 = ‘csmr_notes’; // Table name
$insert_fields2 = array( // Field list, add as many as needed
‘note_csmrID’ => “’{note_csmrID}’”,
‘note_csmr_status’ => “’{note_csmr_status}’”,
‘csmr_note_info’ => “’{csmr_note_info}’”,
);

// Insert record
$insert_sql2 = ‘INSERT INTO ’ . $insert_table2
. ’ (’ . implode(’, ‘, array_keys($insert_fields2)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields2)) . ‘)’;

sc_exec_sql($insert_sql2);