Yes, this is sloppy. I'm not gonna release something nice just for you to leach. I also do not know if this works. It was put together in this post, Sooo... 
Ok, so we gonna do some MySQL Tutorials on dis tread, kay?
Bold - Indicates Field that needs to be changed!
Anyways, To start. Connecting to a database
Code:
<?php
mysql_connect('localhost', 'username', 'password') or die(mysql_error);
mysql_select_db('Database_Name') or die(mysql_error);
?>
What this does;
- Connects to the server name (localhost) in this case
- Logs in to phpmyadmin basicly
- Selects a database that we will edit/modify
- If anything goes wrong, it will display an error
Okay, moving on. Creating a table in mysql...
Open up PHPMyAdmin, and generate/run this code;
Code:
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`text` text NOT NULL,
`ip` varchar(255) NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
What this does;
- Creates a row named ID. This will tell the engine how to display the code later on
- Creates a row named Username
- Creates a row named text where we will process the given text
- Creates a row named IP Which will log the users Ip
- Creates a row named time that logs the time that the post was... posted.
Now, we will need to start programming our actual code. So, to do this, start by making a simple form.
Code:
<?php $postname = 'Set name here.'; ?>
<h3>Comment [Post: <?php echo $postname; ?>]</h3>
<form action="" method="post">
Name: <input type="text" name="username"><br>
Comment: <textarea name="comment" maxlength="200" stlye="max-width:580px;min-width:580px;min-height:80px;max-height:80px;"></textarea><br>
<button>Comment!</button>
What this does;
- Sets a postname which you will have to edit
- Sets two text fields, name and comment
- Sets a button that when clicked will display a certain function, which we will add later
Now, we need to make the actual PHP Part, so add this code to the page in which you made the Html part in...
Code:
<?php
include('config.php');
if(!$comment) {
die('You need to fill in the comment field!');
return false;
}
if($name == "") {
$name = 'Anonymous';
}
$comment = $_POST[comment];
$name = $_POST[name];
if(isset($comment)) {
if(strlen($comment)<="5") {
echo "<error><div style='box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 4px, inset #ED5151 0px 1px 0px;border-radius:5px;padding:5px;border:1px solid red;background:#F01111;display:inline-block;color:white;'>You must enter a message more then 5 characters long!</div><br></error>";
} else {
mysql_query("INSERT INTO comments (username, text, ip, time)VALUES('".$name."', '".comment."', '".$_SERVER[REMOTE_ADDR]."', '".time()."')");
}
}
?>
What this does;
- If the name field is blank, it sets the name to Anonymous
- If the comment field is empty, it quits the operation
- If everything is right, it procedes
- If the comment field is less then 5 letters, it stops and gives an error message
- If this all goes right, then it enters all the necessary data into the database
Now, we need to make a field that actually displays the messages! So, in the same file, create the following code
Code:
<?php
$commentsfetch = mysql_query("SELECT * FROM comments ORDER by id DESC LIMIT 15");
while($row = mysql_fetch_array($commentsfetch)) {
?>
[<?php echo date("d-M-Y H:i:s",$row[time]); ?>]
<?php if(empty($row[username])) {
echo "Anonymous"; }
?>
<br>
<?php echo $row[text]; ?>
What this does;
- Fetches the code and displays 15 of the comments [Editable by you!]
- Echoes the date of the post in []'s, and then displays the username
- If the username spot is still blank, it sets it as anonymous
- It then echoes the text after a enter code basicly
Finishing off...
Well, we finished the actually inside code, but we need something to filter the comments!
Code:
<?php
$inapp = array(
"fuck",
"nigger",
"cunt",
"bitch",
"ass",
"asshole",
"fuckhead",
"xat",
".com"
);
if(check_array($row[text], $inapp) {
str_replace($row[text], "<div style="color: red;"><b>- Sorry, this message contains inapropriate content! -</b></div>");
}
?>
What this does;
- Checks if the row named text includes any inappropriate text
- If it does, then it replaces it with a inappropriate message
Note: You may need to change the $row[text], $inapp around to make it work!
All credits go to me, rage-quit.