check comment for html


Posted on 16th Feb 2014 07:03 pm by admin

hi, I just wanted to check if a comment a user posts contains HTML, and if it does, to not allow it to be posted.

this is my current php, any help would be very much appreciated! thanks.


Code:
<?php

$comment=$_POST['comment'];
$name=$_POST['name'];
$email=$_POST['email'];
$website=$_POST['website'];
$date=date("y/m/d h:i:s");

if($name && $email && $comment){

$sql="INSERT INTO `comments` (`name`, `email`, `website`, `articleid`, `comment`, `datetime`) VALUES ('$name', '$email', '$website', '$id', '$comment', '$date')";
$result=mysql_query($sql) or die(mysql_error());


if($result){


echo "Your comment was posted succesfully on the article n";
echo $rows['title'];
echo '<p><a href="view_article.php?id=';
echo $id;
echo '">Click here to go back to the article.</a></p>';
}else {
echo "Sorry, your comment could not be posted. Please make sure you fill in all the fields marked with *.n";

}
}else {
echo "Sorry, your comment could not be posted. Please make sure you fill in all the fields marked with *.n";
}
?>

No comments posted yet

Your Answer:

Login to answer
173 Like 11 Dislike
Previous forums Next forums
Other forums

mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???

this is the code i got

News script
Hi ...

I am not sure if this is the rite place to post this but if its not sorry

i am

Upload simple problem
Really confused!! I run once and it worked, but when i tried today...it didn't work

Which par

DataTable Help Required
Hi all I am creating an app that utilises and MS Access back end and queries it quite a bit at vario

PHP code for a proxy
I was wondering which function I could use to create an online proxy tool. I was thinking cURL would

Unifying logins of two different scripts
I have two different game scripts which I want to embed on my own site. The problem is I don't want

php/mysql problem
Hey all,

Problem: im trying to setup a shop where people can use a drop-down list to select t

getting weird error..
okay, I'm getting an error on this particular function, something about the syntax in the mysql LIMI

Problem with HTML form
Hello,

I made a HTML form with some fields and check box.
Everything works fine except whe

dynamic table with forms
I have a table that is populated with mysql data and in teh first column there is a raido button tha

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash