ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old May 13th, 2008, 05:36 AM
speedshrew speedshrew is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 speedshrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 53 sec
Reputation Power: 0
Database - Recordset - Search Queries

Hi all,
am new to this, so hope you are all well.
Ive recently got back into a project I started some months ago. Its an information site. It uses a classic ASP link, to aan MS Access backend.
I use a search, but it has two major flaws Id like to get fixed:
1) Case Sensative-need to remove it
2) Punction Marks kill it- a little help?
The code is below:
Code:
<div id="search">
    <form method="post" action="serch.asp"> Enter Location: <input type="text" size="10" name="search" /><input type="submit" name="submit" value="Go" /></form>
  </div>


 <%
    ' see if the form SUBMIT button was pressed
    if request.form("submit") = "Go" then

     Search = request.form("search")
     If (search = "") Then
      SearchVal = true
      Error = true
     End if  %>


      <table>
        <tr>
          <th>Location Name</th>
          <th> Location Address</th>
          <th>Location Rating</th>
          <th>Location Catogory</th>
        </tr>

      <%

        set conn=server.createobject("ADODB.Connection")
        strMDBpath = Server.MapPath("DisabilityNet.mdb")
        conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
        set objRS=server.createobject("ADODB.Recordset")

          ' build the SQL statement
           strSQL = "SELECT * FROM  Locations WHERE LocationName LIKE '%" & Search & "%';"



          'pass the SQL command to the db connection
          objRS.open strSQL,conn,1,2

          ' loop through all the db results
          Do while not objRS.EOF
            response.write "<p>"
            ' output the id field to the screen
          response.write "<tr>"
          response.write "<td>"
          response.write objRS("LocationName")
          response.write "</td>"
          response.write "<td>"
          response.write objRS("LocationAddress")
          response.write "</td>"
          response.write "<td>"
          response.write objRS("LocationRating")
          response.write "</td>"
          response.write "<td>"
          response.write objRS("LocationCategory")
          response.write "</td>"
          response.write "</tr>"

      ' move to the next object in the record set
      objRS.movenext
    ' loop again
    Loop
' close the db connection (important)
%></table>


<%


end if

%>

Thanks in advance

Reply With Quote
  #2  
Old May 13th, 2008, 05:44 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 10,179 micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)micky User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 1 Day 16 h 36 m 26 sec
Reputation Power: 1413
hi and welcome to the forum!!
Cant see where its case-sensitive!!

But for punctuation marks, u need to check for single quotes for every user entered thing, its called sql injections, try this
Code:
Search = Replace(request.form("search"), "'", "")


You can read about it here
http://www.w3schools.com/vbscript/func_replace.asp
Comments on this post
speedshrew agrees!
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #3  
Old May 13th, 2008, 06:01 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,259 sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 23 h 8 m 7 sec
Reputation Power: 769
Hi,

In terms of case sensitivity, you could force everything to uppercase to make sure that you are comparing like for like:
Code:
strSQL = "SELECT * FROM  Locations WHERE UCase(LocationName) LIKE '%" & UCase(Search) & "%';"

Reply With Quote
  #4  
Old May 13th, 2008, 07:37 AM
speedshrew speedshrew is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 speedshrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by sync_or_swim
Hi,

In terms of case sensitivity, you could force everything to uppercase to make sure that you are comparing like for like:
Code:
strSQL = "SELECT * FROM  Locations WHERE UCase(LocationName) LIKE '%" & UCase(Search) & "%';"


Sorry, Ive not made my request clear, it needs to be case INsenastive, so if I enter DOG, Dog or dog, the output is the same.

Reply With Quote
  #5  
Old May 13th, 2008, 07:42 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,259 sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 23 h 8 m 7 sec
Reputation Power: 769
Quote:
Originally Posted by speedshrew
Sorry, Ive not made my request clear, it needs to be case INsenastive, so if I enter DOG, Dog or dog, the output is the same.

Hi,

Have you tested the code I posted?

Basically all it is doing is making sure that anything you search on is forced to uppercase. So if you search for dOg, dog, doG, DoG etc. it will be forced to DOG and compared with DOG. You can display the records in the case in which they are stored, they are only treated as uppercase for the comparison!!

Reply With Quote
  #6  
Old May 13th, 2008, 09:18 AM
keep_it_simple's Avatar
keep_it_simple keep_it_simple is offline
KIS
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jul 2007
Location: USA
Posts: 1,031 keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 8 h 12 m 51 sec
Reputation Power: 340
Send a message via Yahoo to keep_it_simple
Quote:
Originally Posted by speedshrew
Sorry, Ive not made my request clear, it needs to be case INsenastive, so if I enter DOG, Dog or dog, the output is the same.


unfortuantely...if you had just tested sync's suggestion...you would have clearly seen what it's doing...now you have to wait and probably won't get another response vs testing...implementing...moving on...

it's important to test one's suggestion....if it doesn't work..then we can tackle it at another angle....but it would behoove you to take advice from more experienced developers rather than rely on visual logic

on a side note....you can eliminate the special characters with a little used vbs object called regex.....it may look intimidating..but what you are asking for....alphanumeric w/space....is listed in the following link

http://www.15seconds.com/issue/010301.htm
__________________
Please give respect to those that helped solve an issue by clicking on the reputation icon

Reply With Quote
  #7  
Old May 13th, 2008, 09:21 AM
speedshrew speedshrew is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 speedshrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by sync_or_swim
Hi,

Have you tested the code I posted?

Basically all it is doing is making sure that anything you search on is forced to uppercase. So if you search for dOg, dog, doG, DoG etc. it will be forced to DOG and compared with DOG. You can display the records in the case in which they are stored, they are only treated as uppercase for the comparison!!

Thank you!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > Database - Recordset - Search Queries


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway