Jump to content

sql string querying with wildcard


toonz

Recommended Posts

I currently have a php file that runs when users submit text in certain fields around my site. Right now, the file only looks for specifics words I enter into a table, and it only finds exact words. What I want to do is have the sql tring be able to use wildcard values around the {invalid_word} tag so it can find and prevent a user from submitting text if a long word contains the text on my banned list. Like, if I banned the word hair, and someone tried using the word hairball, it would let them. This is what the current php file code is

 

<?php
# **** FIND BAD WORDS INTO THE ENTERED STRING **** #
# @param $str - takes an argument as an string
# match with database keywords
# return true if bad word found
# return false if bad word not found

function findBadWords( $str ){

	$return = false;

	if( strlen( $str ) > 0 ) {
		$sql 		= "SELECT * FROM tbl_invalidunm WHERE MATCH (invalid_word) AGAINST (LCASE('".$str."') IN BOOLEAN MODE)";
		$rs 		= mysql_query( $sql ) or die( "Invalid query - ". mysql_error() );

		if($rs){
			$row_count 	= mysql_num_rows($rs);

			if( $row_count > 0 ) {
				$return = true;
			}
		} // if
	} // if
	return $return;

} // end function 

?>

 

 

Thanks in advance for your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.