Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with insert into statement

Status
Not open for further replies.

markdt

Technical User
Feb 15, 2006
63
GB
Hi people,

Got an issue inserting an SQL statement into access db.
It builds the sql like:

INSERT INTO tblConcern ("comments") VALUES ("something here with a apostrophe ' blah blah")

Basically the problem arrises when someone enters an
apostrophe. My code is below:

comments=Request.Form("txtcomments")
if comments="" then
comments=NULL
else
strSQL=strSQL & "comments,"
end if

My question is do i have to put brackets or something round the variable "comments"?

Thanks

Mark
 
you could replace it with a similar char like: [red]`[/red]

or you could escape the single quote with another one

 
so something like: replace(comments,"'", "`")
or this: replace(comments,"'", "''")

Another reason this is a good idea is what happens if someone entered comments like this:
Code:
'); DROP TABLE Clients; Go;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top