Updating database in ASP

Results 1 to 2 of 2

Thread: Updating database in ASP

  1. #1
    Join Date
    Dec 1969
    Posts
    131

    Default Updating database in ASP

    What is wrong with my update statement? I have a form in which I want to update the fields. When I response.write my SQL to see what&#039s going on, the field that I update looks like this eg....First_Name=&#039&#039. That field is empty. This is incorrect. This is how my SQL looks...........<BR><BR>SQLupdate = "UPDATE tblEmployee SET "<BR>SQLupdate = SQLupdate & "First_Name=&#039" & Form_FName & "&#039,"<BR>SQLupdate = SQLupdate & "Last_Name=&#039" & Form_LName & "&#039,"<BR>SQLupdate = SQLupdate & "Company=&#039" & Form_Company & "&#039,"<BR>SQLupdate = SQLupdate & "Address_1=&#039" & Form_Address & "&#039,"<BR>SQLupdate = SQLupdate & "City=&#039" & Form_City & "&#039,"<BR>SQLupdate = SQLupdate & "State=&#039" & Form_State & "&#039,"<BR>SQLupdate = SQLupdate & "Zip_Code=&#039" & Form_ZipCode & "&#039,"<BR>SQLupdate = SQLupdate & "Email_1=&#039" & Form_Email1 & "&#039,"<BR>SQLupdate = SQLupdate & "Email_2=&#039" & Form_Email2 & "&#039,"<BR>SQLupdate = SQLupdate & "Phone_1=&#039" & Form_Phone1 & "&#039,"<BR>SQLupdate = SQLupdate & "Phone_2=&#039" & Form_Phone2 & "&#039"<BR>SQLupdate = SQLupdate & "WHERE ID=" & Form_ID<BR><BR>Please help...........

  2. #2
    Rob Speicher Guest

    Default RE: Updating database in ASP

    If there&#039s apostrophes in any of your fields, it will cause an error in the SQL statement. Enter this function in your script.<BR><BR> Function InsertAp(str)<BR> If str &#060;&#062; "" Then<BR> If Instr(str,"&#039")&#060;&#062;0 Then<BR> InsertAp = Replace(str,"&#039","&#039&#039")<BR> Else<BR> InsertAp = str<BR> End If<BR> End If<BR> End Function<BR><BR>Then, for any fields you suspect might use apostrophes (Names for O&#039Conner, Possibly Cities, etc.) call them like this:<BR><BR>SQL = SQL & "Field=&#039" & InsertAP(Request.Form("Field")) & "&#039, "

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •