PDA

View Full Version : A comment system w/o SQL



DUB
10-02-2008, 12:56 AM
Okay basically i made a php comment system without any databases it uses a text file to store data. Im learning so its pretty basic :). Anyway here it is if you want to use it.



First of all make a text file and name it what ever you want i named mine comments.txt but you can call it anything. Once you have made your text file CHMOD it to 0777.


Next make a php file, once again you can name it whatever you like i chose to call it comment.php and copy + paste the code below:



<?
$name = $_POST['name'];
$message = $_POST['message'];
@ $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/comments.txt", 'a');
if (!$fp)
{
echo "There was an error! Try again later!";
exit;
}
else
{
$outputstring = "<strong>Name:</strong> " . $name ."<br><strong> Comment:</strong> " . $message .";
fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);
echo "Your post was successful. Click <a href='index.php'>here</a> to continue.";
}
?>Next make another PHP file here i named it index.php as this will be the main page which displays the comments & the form, alternatively you can rename it if you wish.



<html>
<head>
<title>Comment</title>
</head>
<body>
<?php include("comments.txt"); ?> //This is where your comments will be displayed
<hr style="border: 1px solid #000000;">
<form action="comment.php" method="post">
<center><table>
<fieldset>
<legend>Name</legend>
<input type="text" name="name">
</fieldset>
<fieldset>
<legend>Message</legend>
<textarea name="message"></textarea>
</fieldset>
<input class="button" type="submit" value="submit">
</table></center>
</form>
</body>
</html>
Thats all there is to it really :)

Lee
10-02-2008, 10:16 AM
Hey +Rep That Will Help People Who Need One :P Is There No ADMIN Section Where You Can Manage Comments? Or Is That Done By editing comments.txt ?

Nice Though Well Done

Want to hide these adverts? Register an account for free!