Print Page | Close Window

Search help

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2285
Printed Date: 29 March 2026 at 12:01pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Search help
Posted By: Mart
Subject: Search help
Date Posted: 29 April 2003 at 9:51am

Hi im making a search engine for MP3s and this is my SQL code:

strSQL = "SELECT tblMP3.Artist, tblMP3.Track, tblMP3.Genre, tblMP3.Comments, tblMP3.URL, tblMP3.autonum FROM tblMP3 WHERE genre LIKE '%" & request.querystring("cat") & "%' ORDER BY tblMP3.Artist;"

But I need it so if they just type the track it will also come up how do I do that?

Thanks, Martin.




Replies:
Posted By: MorningZ
Date Posted: 29 April 2003 at 10:23am

Well, do you have two different search boxes (for each type)?
Or do you have some sort of selection of "what kind of search" (and do you allow "one", "the other", "both", or "one or the other"?
Or do you want to search both columns with one entered criteria (opens up doors to be very very taxing on the server and slow)?

Speaking of opening up doors, whenever you take user entered data and build a SQL statement, do some sort of check that they don't enter a single tic mark, because that above SQL string build is wide open to someone getting major access on your Database (search google for "SQL Injection" if you want more info on that)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 29 April 2003 at 11:11am

Ok I have one search box which they can enter either a artist or a track or both also it has got to allow artist - track.

Thanks, Martin.



Posted By: michael
Date Posted: 29 April 2003 at 11:31am

strSQL = "SELECT tblMP3.Artist, tblMP3.Track, tblMP3.Genre, tblMP3.Comments, tblMP3.URL, tblMP3.autonum FROM tblMP3 WHERE genre LIKE '%" & strSearchbox & "%' OR Track LIKE '%" & strSearchbox & "%' ORDER BY tblMP3.Artist;"

I took the Request.Querystring out as I agree with Z that you should filter that entry first, thus this way it searches in both fields...



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mart
Date Posted: 29 April 2003 at 11:57am

Ok I've done that now I have another problem, in the database a lot of URLs have my old IP 80.4.220.189 and I have changed services since(I have a new IP).

Is there any way of changing all 80.4.220.189 IP addresses to **.*.***.*** in the tblMP3.URL?



Posted By: Mart
Date Posted: 29 April 2003 at 12:28pm

Thanks for the SQL injection tip, is it just single quotes ' I have to replace with double quotes ''?

Thanks, Martin.



Posted By: MorningZ
Date Posted: 29 April 2003 at 12:39pm

For strings, replace single quotes with two single quotes

ex/
"thisCol LIKE '%" & Replace(strSearch,"'","''") & "%'"

For numbers, like say you are passing an ID across the querystring, I have always used the following method:

Function Clng0( i_str )    'Common function in your code
    Clng0 = 0
    On Error Resume Next
    Clng0 = Clng( i_str )
    On Error Goto 0
End Function

To use it, and you will get rid of any "funny business":
SearchThisID = Clng0( Request.QueryString("PassedID") )



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 29 April 2003 at 12:58pm

Thanks MorningZ, the replace works but you numeric one always gives a null value, Am i doing it right?

Function Clng0( i_str )    'Common function in your code
    Clng0 = 0
    On Error Resume Next
    Clng0 = Clng( i_str )
    On Error Goto 0
End Function


SQL = "FROM somewhere WHERE data LIKE '%" & clng0(request.querystring("ID")) & "%';"



Posted By: Mart
Date Posted: 29 April 2003 at 1:47pm
Oh ignore that last post I thought that function was to get rid of malicious number combinations i.e. getdata.asp?ID=13.


Posted By: michael
Date Posted: 29 April 2003 at 2:32pm
Originally posted by Mart Mart wrote:

Is there any way of changing all 80.4.220.189 IP addresses to **.*.***.*** in the tblMP3.URL?

To change the IP's just run a simple script like
Update table tblMP3.URL set IPFIELD  = '*********' where
ipfield = '80.4.220.189' 



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mart
Date Posted: 30 April 2003 at 9:20am

The thing is the value isn't just 80.4.220.189 it will be something like http://80.4.220.189/minac/punk/0001.mp3 - http://80.4.220.189/minac/punk/0001.mp3 will it still keep the http and the /minac/punk/0001.mp3?

Thanks, Martin



Posted By: Mart
Date Posted: 02 May 2003 at 10:15am
Its alright I fixed it now it took a while but its all fine now...



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net