Hi, I tried to fix this without luck and you guys have bailed me out before so I'm hoping someone might know how to fix this. I have a form with two fields (title and body) and they both cause errors when I use an apostrophe. I tried to replace them with double quotes but it's not working. Here is the code and I appreciate any help or ideas, I'm lost...
What's happening is you aren't escaping the apostrophes. I am assuming this is the block of code that you're referring to:
If NOT rsSaveTemp.EOF Then rsSaveTemp("news_title") = Trim(Request.Form("temptitle")) rsSaveTemp("news_body") = Trim(Request.Form("tempbody")) rsSaveTemp.Update msg = "updated" Else strSQL = "INSERT INTO newsletter ([news_title],[news_body]) Values('"&Trim(Request.Form("temptitle"))&"','"&Trim(Request.Form("tempbody"))&"')" news_title = Replace(news_title, "'" , "''" ) news_body = Replace(news_body, "'" , "''" ) 'Response.Write strSQL ' Response.End
objConn.Execute strSQL msg = "success" End If
If so, change it to look like this:
If NOT rsSaveTemp.EOF Then rsSaveTemp("news_title") = Replace(Trim(Request.Form("temptitle")),"'","''") rsSaveTemp("news_body") = Replace(Trim(Request.Form("tempbody")),"'","''") rsSaveTemp.Update msg = "updated" Else news_title = Replace(Trim(Request.Form("temptitle")), "'" , "''" ) news_body = Replace(Trim(Request.Form("tempbody")), "'" , "''" ) strSQL = "INSERT INTO newsletter ([news_title],[news_body]) Values('"&news_title&"','"&news_body&"')" 'Response.Write strSQL ' Response.End
objConn.Execute strSQL msg = "success" End If
See if that fixes your problem.
Bill Parrott Senior Web Programmer, University of Kansas Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com) Personal Website (www.chimericdream.com)
apostrophes cause all kinds of problems working with SQL Server (and maybe other db's) due to them being 'string delimiters' - you have to convert them to get them into the db, and again to get them out and display them again - just something you'll have to practice a lot and study how other people do it, and try simple and increasingly complex examples until you're good. Even those of us who do it a lot often make mistakes and have to build up and test the strings all the time!
Glad you got it working. Sorry I sort of dropped out, but work has been rather busy this week, so I haven't had a whole lot of time to work on other things.
Bill Parrott Senior Web Programmer, University of Kansas Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com) Personal Website (www.chimericdream.com)