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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with URLEncode 1

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
I have an SQL statement that searches for names in a directory. The names are passed through a variable called "strFacStaffName".

The problem is that we have an employee named "'Connor".

Naturally, the "'" causes an error message, so I tried to use URLEncode. The error message is gone, but the search returns no results.

Here's the code:

dim strFacStaffName
strFacStaffName = Server.URLEncode(Request.Form("FacStaffName"))

cmdTmp.ActiveConnection = objdc
cmdtmp.CommandText = "SELECT Fullname, Title, Department, Phone, Fax, Email, Building, Office FROM Table1 WHERE Fullname2 LIKE '" & strFacStaffName & "%' OR fullname3 LIKE '" & strFacStaffName & "%' OR fullname4 LIKE '" & strFacStaffName & "%' OR fullname5 LIKE '" & strFacStaffName & "%' OR fullname6 LIKE '" & strFacStaffName & "%' Order By Lastname ;"

objrs.Open cmdTmp,,1,3

What exactly is replacing the "'"? What I need is for "O'Connor" to become "Oconnor".
 
If you want to search with the appostrophe included, then on the accepting/processing page, replace the appostrophe with a double appostrophe (not a quote) like this:

<%
Dim name
name = Request.Form(&quot;searchName&quot;)
name = Replace(name, &quot;'&quot;, &quot;''&quot;)
%>


you're taking the variable &quot;name&quot; that contains the name searching for on the site, and replaces all single appostrophe's &quot;'&quot; with double appostrophe's &quot;''&quot;. This will enable it to work with your .asp script.

Hope this helps. -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top