Home > SQL Development > problems with LIKE query

problems with LIKE query



Hi



I have an access database which has a table full of users and their scores and another table full of unacceptable user names.



If a user tries to enter their name as "damn this game" i want the asp to spot that 'damn' is listed in my table (tblSwear) and replace the entire name with "anon".



I read on 4guys from rolla that when using a like statement if u place % around either side of the word u are comparing then it should allow for other characters appearing around the word.



ie '%damn%'

would find "blah-damn-blah"



but for some reason my code below will only detect a user entering purely "damn" despite my use of the % symbol and it will not detect blahdamnblah"




Code:



dim thename
thename=request("rude")
sql = "SELECT * FROM tblSwear WHERE tblSwear.word LIKE '%" & thename & "%'"
'Select * from Tablename where (Firstname) LIKE '%" & FirstNameVar & "%'"
rs.open sql,myconn,3,3
if rs.recordcount > 0 then
response.Write("anon")
else
response.Write(thename)
rs.close
end if






I keep staring at my code and i cant see what the mistake is, i have attached it and the database and files in case any1 has the time to give it a glance.



I will be so grateful for any help.

    
Guest


try %'damn'%






PHP Code:





 LIKE %'" & thename & "'%









NOTE: You will likely do better placing your bad words in an array and then looping through them with the replace function in VBScript/ASP

Was this answer helpful ? Yes No   
Guest


hi Soky



unfortunately it didnt work, thanks anyway.



ScoobyDoo

Was this answer helpful ? Yes No   
Guest


damn

Was this answer helpful ? Yes No   
Guest



Was this answer helpful ? Yes No   
Guest


Sorry man... I don't have time to look into it deeper. It looks like your LIKE statement should work... perhaps it is curser related? I'm not sure.



Give it a day or two and I have no doubt someone here will come to your rescue.

Was this answer helpful ? Yes No   
Guest


thanks anyway, ur response was kinda swift, so u get credit for that!

Was this answer helpful ? Yes No   
Guest


You could try using * instead of % for Access

Was this answer helpful ? Yes No   
Guest


hi Doug



nope, that didn't work either, but thanks for trying!

Was this answer helpful ? Yes No   
Guest


I think your doing this in reverse order.

You have a table full of swear words and searching against them, but if the user enters in damn this game into the field, they in your sql statement your doing this:

sql = "SELECT * FROM tblSwear WHERE tblSwear.word LIKE '%dame this game%'"



This is the reason why you aren't getting a match.

I would suggest you use Soky's suggestion on using an array with replace to find and replace instances of swear words.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved