Jump to content

Comment Posting Script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
jthom263

jthom263

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Hello

Does Anyone Know of Any Good Tutorials On Making A Script So I Can Post Comments On My Website????

Any Help Would Be Dearly Appreciated. :):lol:
Thanks. Jack
:)

#2
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
No. but they are not that hard to make. If you use tutorials for every thing than you will never become efficiant (i had frineds at Uni that only ever coppied tutorials, now they still can't do any programming and they have been at it for 4 years now.). Why don't you sit down with penciel and paper and engineer it. Than try to build it by making your own code and if you run in to problems you can ask more specific questions on here. You will learn a lot more that way.
Posted Image

#3
jthom263

jthom263

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Yeah I Would But So Far I Only Know The Very Basics Of PHP As In Like The Hello World And Basic Functions And I Would Like To Implement a Comment Posting Script On A New Website I Am Developing And I Still Have A Lot To GO With Php. So What Do U suggest i do????
:)

#4
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
One thing is right, you don't need to do all with tutorials, though tutorials are good for learning purpose and learning the CORRECT way to do things.

But comment posting scripts aren't hard to make at all, look how I just use some basic PHP/MySql to get it done in an example:

<?php
if($_POST) { // Did user attempt to post a comment?
 
$author = $_POST['username'];
$timestamp = time(); //unix timestamp of curr time
$message   = $_POST['message'];
 
$post_it  = mysql_query("INSERT INTO comments(author,message,timestamp)VALUES('".mysql_real_escape_string($author)."', '".mysq_real_escape_string($message)."', '$timestamp') ");
 
if($post_it) {
   echo "Comment successfully posted!";
}else{
   echo "Mysql eror occured while attempting to post your comment.";
}
 
}else{
 
//show the form
 
}
?>

Very basic really and not hard at all, though you might want to add lots of things and checks before executing the actual query but this is just basicly how it works ( Ofcourse you'll need a database with a table including these fields such as author,timestamp and message as used in this example ).

#5
jthom263

jthom263

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Thank You Very Much Skyfe :) I Think I Get The Basic Idea Of How I Should Go About Making The Sql Databases And The Form For This Script, u should Be A Teacher. :w00t: I Will Post The finished Scripts On Here For U To Have A Look At And Make Suggestions. :)
:)

#6
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Np, created small example of how to retrieve all comments:

<?php
mysql_connect("localhost", "root", "password");
mysql_select_db("database_name");
$get_comments = mysql_query("SELECT * FROM comments");
 
//select all comments
//now retrieve all found comments by the query of $get_comments
//for each result found ( each comment entry/row) put the info inside the var $comment
//as an array, like: $comment[field_name] = value, so for example $comment['author'] will
//contain the author name of the comment
 
while($comment = mysql_fetch_assoc($get_comments)) { //retrieve all comments, one per time
echo "
<div style='margin: 10px; border: 1px solid #BBBBBB; width: 650px;'>
<p>Comment posted by ".$comment['author']." on ".date("m-d-y", $comment['timestamp'])."</p>
<p>".nl2br($comment['message'])."</p>
</div>
";
}
?>

Though you might want to include post_id fields if you mean to have comments to multiple posts.
</SPAN>

#7
jthom263

jthom263

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Thank - You Very Much :w00t:
:)