[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Inserting Apostrophe generates error

When I insert or update any record in a table from any ASP page that contains some form input text element, at the time of updating record that contains any apostrophe generates error.
I replaces single qoute to two times and then save. and now it saves.
but what is the solution of this problem.
0
AhmadKhan
Asked:
AhmadKhan
1 Solution
 
xenon_jeCommented:
The solution is that you need to 'prepare' a string before saving. So any ' character needs to be doubled.
This is the solution which (if I understood well) you already found........
0
 
crosmillCommented:
SQL looks for the ' to open and close strings, 'string', if you have an ' in the string it breaks the string abnormally 'st'ring' causing an error. depending on how your coding it you can use Replace(variabl, "'" "''") which will store the ' as a single not a double ''.
0
 
crosmillCommented:
Didn't spot you were using ASP

Try this

Function RequestFormAp(name)
          temp = Request.Form(name)
          temp = replace(temp,"'","''")
          RequestFormAp = temp
     End Function
     
     addid = RequestFormAp("addid")
     
     add1 = RequestFormAp("add1")
     add2 = RequestFormAp("add2")
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lengreenCommented:
Pretty much the same as above just pass any strings to be inserted / updated to the SQLSafe function

Function SQLSafe(TheString)
     SQLSafe = Replace(TheString, "'", "''")
End Function

thequery = "insert into tblname (TextField) values (" & SQLSafe(myDirtyString)&")"
0
 
CleanupPingCommented:
AhmadKhan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
monosodiumgCommented:
No comment has been added to this question in more than 268 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: xenon_je http:#8158507

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

monosodiumg
EE Cleanup Volunteer
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now