Jump to content

Comments


funkyjunky

Recommended Posts

Hey again everyone.Now im REALLY out of my depth.I want to create a system to make commenting possible on posts in my news page.I know I will need a SQL database (My host provideds one) and PHP script...How should I start!!

Link to comment
Share on other sites

Well, you could have a the page with an area to display comments as well as a small form that sends the data to another page, which stores the comments in the mySQL database before redirecting.comments.php

<!-- HTML tags, header, etc... --><?php$con = mysql_connect("localhost", "username", "password"); //Connect to the mySQL servermysql_select_db("yourdb"); //Select the database$result = mysql_query("SELECT * FROM comments_table LIMIT 10"); //Get the last 10 commentswhile ($comment = mysql_fetch_assoc($table)) { //Loop through them	echo "<b>" . date("d/m/y h:ia", $comment['date']) . ":</b> {$comment['comment']}<br />\n"; //Display them!}?><!-- This is the form --><form action="addcomment.php" method="post">	<input type="text" name="comment" /> <input type="submit" value="Add Comment" /></form><!-- End body, html tags, etc... -->

addcomment.php

<?php$con = mysql_connect("localhost", "username", "password"); //Connect to the mySQL servermysql_select_db("yourdb"); //Select the databasemysql_query("INSERT INTO commments_table (date, comment) VALUES (" . time() . ", '{$_POST['comment']}')"); //insert the comment into the tableheader("location: comments.php"); //Redirect back to comments.php?>

Your table is called comments_table and it has two fields: date INT(16) and comment VARCHAR(256). You can create them using phpMyAdmin through your host control panel.There - code for the simplest comments system ever :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...