|
Posted by Jerry Stuckle on 05/14/07 14:56
Johnny BeGood wrote:
> "Michael Fesser" <netizen@gmx.de> wrote in message
> news:620e43h7j285ii1h6glq2ak8lnoj5gs273@4ax.com...
>> // query string with 2 placeholders
>> $query = 'INSERT INTO Tasks (TaskType, Details) VALUES (?, ?)'; - this
>> throws a field count error, silly me?
>>
>> // prepare the statement
>> $stmt = odbc_prepare($odbc, $query);
>>
>> // pass all parameters in an array and execute the statement
>> if (!odbc_execute($stmt, array($tasktype, $taskdetails))) {
>> ...
>> }
>>
>> HTH
>> Micha
>
> Hi Micha,
>
> If I enter didn''t it works, if I enter didn't it comes back with the
> same error as before
> [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
> operator) in query expression ''didn't',
>
> This is what I have
> $query = 'INSERT INTO Tasks (TaskType, Details) VALUES ($tasktype,
> $taskdetails)';
> $stmt = odbc_prepare($odbc, $query);
> if (!odbc_execute($stmt, array($tasktype, $taskdetails)))
> {
> echo odbc_errormsg();
> }
>
> Where am I going wrong (:
>
> Cheers
>
(Top posting fixed)
The single quote is defined by SQL as the separator (enclosing
character) for string values. The string you're trying to insert, by
the time it gets to SQL, would be:
'It didn't work'
Note the mismatched single quotes. Some languages, like C and PHP,
escape special characters like this with a backslash, i.e.
'It didn\'t work'.
SQL does it a little differently - you double the apostrophe, so it
comes out as:
'It didn''t work'
And this does work just fine.
P.S. Please don't top post. Thanks.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|