I’d like to store banned words in a database to later determine if some word is present (hence being a banned word, which should be censored).
Word input form (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>
PHP code (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";
?>
Let’s say we banned the word ugly. Now I want do this :
<?PHP
require_once("config.php"); // db conn
$qry = "select * from my_table";
$result = mysql_query($qry) or die($qry);
$test = "ugly"; // Example
if ($test == any of the words in the db my_table){
echo "banned";
}else{
echo "passed";
{
?>
How to do this? There are many added words in my_table :
id,bad (1,'ugly')
id,bad (2,'sick')
id,bad (3,'manal')
id,bad (4,'fog')
You should attempt to select the word from the database, this is much faster than having to go through an array.
Something like this should work.