Single Quotes in CGI
April 7, 2006 12:00 AM
Excellent question. This is how you do it....I will explain in theory how it works, then I will give you the line of code that makes it work. Apostrophes are treated as terminators in SQL, so it fails on the Insert into. What you need to do is BEFORE you execute the sql statement replace the apostrophe with something else you don't use that SQL doesn't care about. I frequently use the tilda ~ for that purpose. So if you wanted the following to go into the db:"I don't know the answer." what will really go into the database is "I don~t know the answer." That eliminates the problem. immediately after the linequestion3=request.form("question3")put the following line:question3= Replace(question3, "'", "~")Now the only problem is getting the data out of the database to look right....just reverse it....when you grab the data out of the database the next line needs to be:question3= Replace(question3, "~", "'")If you have any questions, email me.
Discussions have been disabled for this post