TGWSE_GY Posted August 14, 2009 Share Posted August 14, 2009 :facewall: :facewall: :facewall: :facewall: Hi Guys, First I want to say yes the language is part of the script to ignore comments with these 7 cuss words in them. However it is still going to my else and adding it to the table and I just want it to stop and go the the defined header location if any of the 7 words are found. Can anyone tell me why its adding to the database? Here is the code: <?php include('db_con.php'); $filename = $_POST['filename']; $comment = $_POST['comment']; $currentpage = $_POST['currentpage']; $adminaddress = "http://www.hmtotc.com/private/george/projects/dandj/admin/admin.panel.php"; $shit =substr_count($comment, "shit"); $piss =substr_count($comment, "piss"); $fuck =substr_count($comment, "fuck"); $cunt =substr_count($comment, "cunt"); $cocksucker =substr_count($comment, "cocksucker"); $motherfucker =substr_count($comment, "motherfucker"); $tits =substr_count($comment, "tits"); if ($shit || $piss || $fuck || $cunt || $cocksucker || $motherfucker || $tits){ header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage); } elseif ($comment === "comment"){ header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage); } else { $imgcommentquery = "INSERT INTO `comments` ( imgname , comments ) VALUES ('$filename', '$comment')"; mysql_query($imgcommentquery); $to = "george@visualrealityink.com"; $subject = "New Comments"; $body = "<p>New Comments have been made please click the link below to allow or delete comments</p><p>$adminaddress</p>"; mail($to, $subject, $body); header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage); } /*$to = "photographer@dnjphotography.net"; $subject = "New Comments"; $body = "<p>New Comments have been made please click the link below to allow or delete comments</p><p>$adminaddress</p>"; mail($to, $subject, $body); */ ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170258-filtering-out-unwanted-words/ Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2009 Share Posted August 14, 2009 A much cleaner method. <?php preg_match_all('/(shit|piss|fuck|cunt|cocksucker|motherfucker|tits)/', $comment, $result); if(count($result[1])) { // bad words found print "Rinse your mouth out"; } else { // no bad words print "You are a good boy"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170258-filtering-out-unwanted-words/#findComment-898122 Share on other sites More sharing options...
Appzmaster Posted August 14, 2009 Share Posted August 14, 2009 Maybe you should try reformatting that if statement try something like if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; elseif code to be executed if condition is false; else code to be executed if condition is true; //And so on.... Split each of the bad words up with the elseif but hey I am fairly new to this so that's just my 2 cents. Quote Link to comment https://forums.phpfreaks.com/topic/170258-filtering-out-unwanted-words/#findComment-898125 Share on other sites More sharing options...
TGWSE_GY Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks neil worked like a charm!!!!!!! Appzmaster thanks but neils solution is what I needed, and the if statement structure is fine. Especially now that Im using preg match all. Thanks Guys! Quote Link to comment https://forums.phpfreaks.com/topic/170258-filtering-out-unwanted-words/#findComment-898141 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.