Here is the script:
<?php
$dbConn = odbc_connect("mailnews", "" ,"");
$nTitle = stripslashes($nTitle);
$nBody = stripslashes($nBody);
$nUser = stripslashes($nUser);
if($nChecked == "1") {
$qryStr = "INSERT INTO news ( EDATE, EXPIRES, DATEEXPIRES, TITLE, BODY, EUSER )
VALUES ( DATE(), TRUE, '$nExpiresOn', '$nTitle', '$nBody', '$nUser' ) ";
} else {
$qryStr = "INSERT INTO news ( EDATE, TITLE, BODY, EUSER ) VALUES ( DATE(),
\"$nTitle\", \"$nBody\", \"$nUser\" ) ";
}
echo "$qryStr";
odbc_exec($dbConn, $qryStr);
?>
I want to insert apostrophe's into my little database. For instance the user enters
this in the fields provided:
My Title's Name
This body text hasn't got nothing.
My Name's Cool
The resulting SQL string is this:
INSERT INTO news ( EDATE, TITLE, BODY, EUSER ) VALUES ( DATE(), "My Title's Name",
"This body text hsn't got nothing.", "my Name's Cool" )
I'm trying to insert into TEXT fields in Access 2000.
Using Access's SQL builder (Query thingy) it indicates that you can surround fields in
"" that have ' in them without the need for escaping.
Here is the error:
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] '' is not a valid name.
Make sure that it does not include invalid characters or punctuation and that it is
not too long., SQL state 37000 in SQLExecDirect in C:\PMPCWEB\mail\addnewsitem.php on
line 17
Here is the other method I have tried:
INSERT INTO news ( EDATE, TITLE, BODY, EUSER ) VALUES ( DATE(), 'My Title\'s Name',
'This body text hasn\'t got nothing.', 'My Name\'s Cool' )
With this error:
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression ''My Title\'s Name', 'This body text hasn\'t got
nothing.''., SQL state 37000 in SQLExecDirect in C:\PMPCWEB\mail\addnewsitem.php on
line 17
I give.. Anyonve have some ideas for me please?
Thanks in advance
RDB