Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending with URLEncode...?

Status
Not open for further replies.

adamsoderqvist

Programmer
Sep 8, 2001
136
SE
Hi,

I have an SQL string saying:

[
Dim strSQL
strSQl = "SELECT * FROM tblMembers WHERE Message LIKE '%" & strSearchText & "'% ORDER BY PostDate"
]

Now, when I send this to another page using the query string, it returns: (on the new page)

[
"SELECT * FROM tblMembers WHERE Message LIKE ' (some crazy character...) ' ORDER BY PostDate"
]

This is fixed with the "Server.URLEncode"-command, I know, but how do I use it so that the outcome of my select-statement will be the same as intended?

I've tried, but don't seem to reach a good result...
 
The string is automatically encoded and then unencoded for you by IIS. I take it you have written the final string output to the screen? If you are first encoding it, that could be your problem. There are scripts that can unencode it, but your issue might be simpler than that. Jonathan Galpin
 
Well, I first tried to write the string to the second page, with the result being as displayed above. According to "rumors" the answer to that is the URLEncode, which should enable the user to send these types of strings across the asp documents with the result of generation of a correct string in the end.

I run PWS - could that be an issue, as well?
 
Your problem is that the % is a part of the encoding to make the url travel safely over http. My advice is that you should be able to design your pages to not have a sql statement sent over that way. Describe the pages, and I bet a simple solution will be available.

********************************
You should have NO use for these:
********************************
Formatted for vb, adjust for vbscript

Public Function makeSqlSafe(ByVal sqlStr$)
Dim strTemp, strChar As String
Dim nTemp, nAsciiVal As Integer
strTemp = ""
strChar = ""

For nTemp = 1 To Len(sqlStr$)
nAsciiVal = Asc(Mid(sqlStr$, nTemp, 1))
If ((nAsciiVal = 34) Or (nAsciiVal = 39)) Then ' 34 = " and 39 = '
strTemp = strTemp & Chr(32) ' change to space
Else
strTemp = strTemp & Chr(nAsciiVal)
End If
Next
makeSqlSafe = strTemp
End Function

Public Function URLEncode(ByVal strData$)
Dim strTemp, strChar As String
strTemp = ""
strChar = ""
Dim nTemp, nAsciiVal As Integer

For nTemp = 1 To Len(strData$)
nAsciiVal = Asc(Mid(strData$, nTemp, 1))
If ((nAsciiVal < 123) And (nAsciiVal > 96)) Then
strTemp = strTemp & Chr(nAsciiVal)
ElseIf ((nAsciiVal < 91) And (nAsciiVal > 64)) Then
strTemp = strTemp & Chr(nAsciiVal)
ElseIf ((nAsciiVal < 58) And (nAsciiVal > 47)) Then
strTemp = strTemp & Chr(nAsciiVal)
Else
strChar = Trim(Hex(nAsciiVal))
If nAsciiVal < 16 Then
strTemp = strTemp & &quot;%0&quot; & strChar
Else
' the %20 character is replaced with + to emulate the IIS server.urlencode
If strChar = &quot;20&quot; Then
strTemp = strTemp & &quot;+&quot;
Else
strTemp = strTemp & &quot;%&quot; & strChar
End If
End If
End If
Next
URLEncode = strTemp
End Function Jonathan Galpin
 
Thanx, but I managed to solve it!
I used the URLEncode statement and it worked. In my code I'm forced to parse SQL statements to other pages (long story...), but now it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top