Here is my try to create banned words tool but in last step i’m getting error.
1 – Created simple form to input the words to be banned (ban.php)
<form name="form" method="post" action="add.php">
<textarea name="bad" id="bad"></textarea>
<input type="submit" name="submit" id="submit" size="12" value="submit">
</form>
2 – Now will post it through db (add.php)
//DB Connection
require_once("config.php");
$bad = $_POST['bad'];
$bad = mysql_real_escape_string($bad);
$bad = nl2br($bad);
$bad = explode("<br />",$bad);
foreach ($bad as $value)
{
$sql = "update my_table set words='$value'";
mysql_query($sql, $conn) or die(mysql_error());
}
echo "Done words added";
3- Now how to apply it ! check this where i can not do !
i wanna say when $test="shit"; then if $test == any of the words added then give banned message and if not then give passed message.
<?php
//DB Connection
require_once("config.php");
//example
$test = "shit";
$qry = "select * from my_table";
$result = mysql_query($qry) or die($qry);
$line = mysql_fetch_array($result);
$words = nl2br($line['words']);
$words = str_replace('<br />', '', trim($words));
if ($test == $words)
{
echo "bannd";
}
else
{
echo "passed";
}
The problem is i do not know how to compare $test with every single word added since all are stored in db like this
INSERT INTO `my_table` VALUES (1, 'bad\r\nshit\r\ndrugs');
so any help ~thanks
get all the results in an array from the database for example.
and then you can check it like this.
P.S : you should re-consider to design your database table on how you will store the records of banned words. better of you store one record in one row. for example.
this way all it will be easier for you to maintain records.