Jump to content

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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...