Objective : I'd like to store certain words inside database table as banned words to not to be used within posts.
I've asked how to apply banned words application using database Banned words application using database table and thanks for all answers.
But i've some changes would like to apply but 1st here is the new code
1- Created simple form to input the words to be banned (ban.php)
<form name="form" method="post" action="add.php">
<input type="text" name="bad" id="bad">
<input type="submit" name="submit" id="submit" size="12" value="submit">
</form>
2 - Now will post it through db (add.php)
<?PHP
require_once("config.php"); // db conn
$bad = $_POST['bad'];
$bad = mysql_real_escape_string($bad);
$sql= "insert into my_table set bad='$bad'";
mysql_query($sql, $conn) or die(mysql_error());
echo "Done bad word added";
?>
3- Example (1) ~ thanks to Robjong for previous help ~
<?PHP
require_once("config.php"); // db conn
$test = "ugly"; // Example
$qry = "SELECT * FROM `my_table` WHERE bad='{$test}'"; // select by value
$result=mysql_query($qry);
if( mysql_num_rows( $result ) ){ // we have a row with the 'bad' word
echo "banned";
}else{
echo "passed";
}
?>
Now my question Example (2)
What if i want to say if any of the stored words in my_table
is found within $test
then give echo "banned";
Just like this
<?PHP
require_once("config.php"); // db conn
$test = "hello world this is sentence with ugly word"; // 'ugly' word found
if( any stored words in my_table found within $test ){
echo "banned";
}else{
echo "passed";
}
?>
so how to do example (2) ?! that would helps me a lot.