Currently, I'm peppering form submissions to account for single quotes & other garbage.
$form_field_value= str_replace("'", "''", stripslashes($form_field_value));
It is to prep the value for insertion using:
$insert_sql = "insert into table (field) values ('".$form_field_value."')";
odbc_exec($conn, $insert_sql);
Essentially, I want to use placeholders for these insert/update statements.
I tried defining $par1
and $par2
as literals and then executing this
$insert_sql = "insert into table (field,txt) values (?,?)";
odbc_exec($conn, $insert_sql, $par1, $par2);
It failed and gave me this error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error, SQL state 07001 in SQLExecDirect in test.php on line 10
Line 10 is the exec statement.
I can't find syntax for using placeholders with this odbc driver. Any suggestions?
The $conn
connection variable is working fine.
EDIT:
Last attempt still failing - odbc_execute() is an undefined function. I have to use odbc_exec()
$par1="eggs";
$par2="milk";
$insert_crs = "insert into table (field,txt) values (?,?)";
$stmt = odbc_prepare($conn, $insert_sql);
odbc_exec($stmt, array($par1, $par2));