Pass a special character (') in a string

Hi There,

i have a table where i copy a part of a record from another table in.

i use the code:

$insert_table = ‘ILP_rooster_TEMP’; // Table name
$insert_fields = array( // Field list, add as many as needed
‘wk_id’ => “’{wk_id}’”,
‘ev_id’ => “’{ev_id}’”,
‘wk_titel’ => “’{wk_titel}’”,
‘wk_conf_container’ => “’{wk_conf_container}’”,
);

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

sc_exec_sql($insert_sql);

Works fine. but with some records iget an error. i saw that that record had a field uses ’ in the text that causes the error.

so i have to modify ( i think this part of ) the code

‘wk_titel’ => “’{wk_titel}’”,

to get it working so that it also copy’s html text with ’ in it. but, can’t get it working…

any suggestions?

You need to escape the ’ in your field

use ‘wk_titel’ => “’” . str_replace("’","’’",{wk_titel}) . “’”,

2 Likes

Your’re a lifesaver! thanks. was already busy with declare but that did’nt do the trick this is much better. many thanks!