Forums

This topic is locked

I need Help! Quotes in Database!

Posted 26 Sep 2001 22:01:46
1
has voted
26 Sep 2001 22:01:46 Glenn Campbell posted:
<font face='Courier New'>
I am having a problem, and I am stumped. The code looks right, and I still cannot figure out why I cannot send quotes " to the SQL database.

What is happening is when entering information into the database, it cuts out everything after the quotes " Here is what my code looks like ... LONG


&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;%
Dim dtNow
dtNow = Now()
%&gt;
&lt;%
' *** Logout the current user.
MM_Logout = CStr(Request.ServerVariables("URL") & "?MM_Logoutnow=1"
If (CStr(Request("MM_Logoutnow") = "1" Then
Session.Abandon
MM_logoutRedirectPage = "../hdloggedout.asp"
' redirect with URL parameters (remove the "MM_Logoutnow" query param).
if (MM_logoutRedirectPage = "" Then MM_logoutRedirectPage = CStr(Request.ServerVariables("URL")
If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_newQS = "?"
For Each Item In Request.QueryString
If (Item &lt;&gt; "MM_Logoutnow" Then
If (Len(MM_newQS) &gt; 1) Then MM_newQS = MM_newQS & "&"
MM_newQS = MM_newQS & Item & "=" & Server.URLencode(Request.QueryString(Item))
End If
Next
if (Len(MM_newQS) &gt; 1) Then MM_logoutRedirectPage = MM_logoutRedirectPage & MM_newQS
End If
Response.Redirect(MM_logoutRedirectPage)
End If
%&gt;
&lt;!--#include file="Connections/hdpoc.asp" --&gt;
&lt;%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="CSR,REPORT,Admin"
MM_authFailedURL="hdValidate.asp"
MM_grantAccess=false
If Session("MM_Username" &lt;&gt; "" Then
If (false Or CStr(Session("MM_UserAuthorization")="" Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization")&gt;=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?" &gt;= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL"
if (Len(Request.QueryString()) &gt; 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%&gt;
&lt;%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL")
If (Request.QueryString &lt;&gt; "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%&gt;
&lt;%
' *** Insert Record: set variables (With IDENTITY Funtionality. Author George Petrov)

If (CStr(Request("MM_insert") &lt;&gt; "" Then

MM_editConnection = MM_hdpoc_STRING
MM_editTable = "dbo.hdpoc"
MM_editRedirectUrl = "hd_ticketsubmitted.asp"
MM_fieldsStr = "openedby|value|opendate|value|acctnumber|value|custlastname|value|custfirstname|value|custaddress|value|custcity|value|custstate|value|custzip|value|custphone|value|altphone|value|node|value|opentime|value|problemcode|value|details|value|assignto|value|Status|value|LastUpdate|value|UpdatedBy|value"
MM_columnsStr = "OpenedBy|',none,''|OpenedDate|',none,''|AcctNumber|',none,''|CustLastName|',none,''|CustFirstName|',none,''|CustAddress|',none,''|CustCity|',none,''|CustState|',none,''|CustZip|',none,''|CustPhone|',none,''|AltPhone|',none,''|Node|',none,''|TimeSent|',none,''|ProblemCode|',none,''|Details|',none,''|AssignedTo|',none,''|Status|',none,''|LastUpdate|',none,''|UpdatedBy|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Insert Record: construct a sql insert statement and execute it (With IDENTITY Funtionality. Author George Petrov)

If (CStr(Request("MM_insert") &lt;&gt; "" Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
If (i &lt;&gt; LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.CommandText = "SELECT @" & "@IDENTITY AS Ident"
Set rsLastIdent = MM_editCmd.Execute
if NOT rsLastIdent.EOF then
strLastIdent = rsLastIdent.Fields.Item("Ident".Value
Session("NewID" = strLastIdent
end if
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;

I know that the replace function is supposed to correct the problem, and it has this information on the code, so why am I not able to insert the entire thing into the database. All of my other pages are working just fine.

</font id='Courier New'>

Reply to this topic