Active Server Pages Programming (ASP)/apostrophie error

Advertisement


Question
QUESTION: if i input a name say O'neill in the User textbox insert statement produces an error.. Please can you assist? thanks
If Request("submit") = "Add" Then
  sSQL = "Insert into Detail values('" & Request("SerialNumber")& "', '" & Request("Equipment") & "','" & Request("User")& "', '" & Request("Office")& "','" & Request("Manufacturer")& "', '" & Request("Model")& "', '" & Request("CPU")&"', '" & Request("RAM")& "','" & Request("VGACard") & "', '" & Request("HardDisk")&"')"
 

  oConn.Execute(sSQL)
  Response.Write("<strong>The Record has been added to the Details Database </strong><BR><BR>")
End If

oConn.Close
Set oRS = Nothing
Set oConn = Nothing
%>


ANSWER: Hi,

When you insert or update databases they won't except the ' so you have to do a replace like this replace(request("user"), "'","''")

That should do the trick

---------- FOLLOW-UP ----------

QUESTION: where in the code should i place replace(request("user"), "'","''")

Answer
replace
sSQL = "Insert into Detail values('" & Request("SerialNumber")& "', '" & Request("Equipment") & "','" & Request("User")& "', '" & Request("Office")& "','" & Request("Manufacturer")& "', '" & Request("Model")& "', '" & Request("CPU")&"', '" & Request("RAM")& "','" & Request("VGACard") & "', '" & Request("HardDisk")&"')"

with this:-

sSQL = "Insert into Detail values('" & Request("SerialNumber")& "', '" & Request("Equipment") & "','" & replace(Request("User"),"'","''")& "', '" & Request("Office")& "','" & Request("Manufacturer")& "', '" & Request("Model")& "', '" & Request("CPU")&"', '" & Request("RAM")& "','" & Request("VGACard") & "', '" & Request("HardDisk")&"')"

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ashley Brazier

Expertise

Main focus is ASP, SQL Server 2000 & 2005

Experience

Over 6 years experience.

Education/Credentials
BCs Honours Software Design and Networks

©2012 About.com, a part of The New York Times Company. All rights reserved.