Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How do you create a Comment Box? Script help please

  1. #1
    pandaxx's Avatar
    pandaxx is offline x10Hosting Member
    Join Date
    Jul 2008
    Location
    US OF A
    Posts
    28

    Question How do you create a Comment Box? Script help please

    I've been scouring the web for a code/tutorial to make a comment box. You know, like the kind you see on the bottom of blogs to submit a comment.

    All I know so far is that you need MySQL and PHP, but I'm not sure how they connect ...

    Could someone perhaps enlighten me or maybe link me to a tutorial for how MySQL works, how PHP works, how to create a comment box or best yet to a code for one? (My Googling skills are failing me now, sadly.)

    Thank you!

    PS: I would like one made from CSS/HTML, not hosted by another website =/

  2. #2
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: How do you create a Comment Box? Script help please

    Hum, I don't have time for a complete code for you, but here's something I use on my website to add blog-like articles. I did a bit of editing to make it easier for you to use and to fit a bit more with what you're looking for, I hope you'll be able to work from that.

    Code:
    <?php
    //Form already sent?
    if (isset($_POST['add']))
        {
     
    //If so, connect to database
    $connection = mysql_connect("host","user","password"); 
    if ( ! $connection ) 
    die ("connection failed"); 
    $link="database_name"; 
    mysql_select_db($link) or die ("no connection");
     
    // Create variables
    $name = $_POST['name'];
    $title = $_POST['title'];
    $comment = $_POST['comment'];
     
    //Check if all the info is there and send it
    if (isset($name) AND $name !="" && isset($title) AND $title !="" && isset($comment) AND $comment !="")
     {
    mysql_query("INSERT INTO table_name (name, title, comment)
    VALUES ('$name', '$title', '$comment')");
     }
     
    //Close connection
    mysql_close($connection);
     
    // Here you can echo a confirmation message, redirect somewhere or whatever
     
    }
     
    else {
    //If the form has not been sent, show it to the user
     
    //Connecting to database
    $connection = mysql_connect("host","user","password"); 
    if ( ! $connection ) 
    die ("connection failed"); 
    $link="database_name"; 
    mysql_select_db($link) or die ("no connection");
     
    echo "
    <FORM method=post action=\"page.php\">
    <table>
    <tr>
    <td>
    Name&nbsp;:&nbsp;
    </td>
    <td>
    <INPUT type=text name=\"name\">
    </td>
    </tr>
    <tr>
    <td>
    Title&nbsp;:&nbsp;
    </td>
    <td>
    <INPUT type=text name=\"title\">
    </td>
    </tr>
    <tr>
    <td>
    Comment&nbsp;:&nbsp;
    </td>
    <td>
    <TEXTAREA cols=50 rows=15 name=\"comment\"></TEXTAREA>
    </td>
    </tr>
    <tr>
    <td>
    <INPUT type=\"submit\" name=\"add\" value=\"Send\">
    </td>
    </tr>
    </table>
    </FORM>
    ";
    }

    In your case, you would have to keep in mind that it's for a blog. Which means, you could/should add entries in your database to indicate to which blog entry this comment belongs.

    For example, you could have a "blog" table with the entries "id", "date", "title", "text" and a "comments" table with the entries "id", "name", "title", "comment", "blog" and, if you want, a "date" as well but you'd have to use a timestamp or something to get it, which I don't know much about.
    The "blog" entry would be the one where you say to which blog it refers, either using the blog's ID, name or else. And getting that information depends pretty much on how you display your blog...

  3. #3
    Hazirak's Avatar
    Hazirak is offline x10 Sophmore
    Join Date
    Dec 2007
    Location
    Georgia
    Posts
    197

    Re: How do you create a Comment Box? Script help please

    You don't need MySQL, you can simply have the script dump the comments to a text file and then read those. They're public anyways, so there's no real harm done if someone manages to get to them. No sense in making things more complicated than they need to be.

    I actually have a simple comment script I wrote for a client at one point. Feel free to PM me for it if you still haven't found an answer by the time you read this, you're more than welcome to edit it as needed.

  4. #4
    marshian's Avatar
    marshian is offline x10 Elder
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: How do you create a Comment Box? Script help please

    Quote Originally Posted by Hazirak View Post
    You don't need MySQL, you can simply have the script dump the comments to a text file and then read those. They're public anyways, so there's no real harm done if someone manages to get to them. No sense in making things more complicated than they need to be.

    I actually have a simple comment script I wrote for a client at one point. Feel free to PM me for it if you still haven't found an answer by the time you read this, you're more than welcome to edit it as needed.
    You're right, no sense in making things more complicated than they need to be -> use mysql, it's faster and easier
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  5. #5
    Hazirak's Avatar
    Hazirak is offline x10 Sophmore
    Join Date
    Dec 2007
    Location
    Georgia
    Posts
    197

    Re: How do you create a Comment Box? Script help please

    Quote Originally Posted by marshian View Post
    You're right, no sense in making things more complicated than they need to be -> use mysql, it's faster and easier
    ... And then to someone who doesn't even know SQL or how to interact with a MySQL server with PHP, it would likely be 'faster and easier' to just use a plain-text-based system.

  6. #6
    woiwky is offline x10 Lieutenant
    Join Date
    Mar 2008
    Posts
    390

    Re: How do you create a Comment Box? Script help please

    Chances are he'd have a harder time developing a file-based comment system than if it were db-based. Especially since it seems like his php experience is minimal at most.

    Something like this only requires basic knowledge of mysql insert, update, and select commands along with basic phpmyadmin knowledge(which is mostly intuitive). What's more, learning mysql will benefit him far more in the long run.

    Mysql is more organized, less error-prone, and, in my opinion, the easier option. And since he asked for tutorials on it, here are a couple that should be adequate for creating something like this:

    http://www.w3schools.com/php/php_mysql_intro.asp
    http://www.tizag.com/mysqlTutorial/
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  7. #7
    pandaxx's Avatar
    pandaxx is offline x10Hosting Member
    Join Date
    Jul 2008
    Location
    US OF A
    Posts
    28

    Re: How do you create a Comment Box? Script help please

    Thanks everyone!<3

  8. #8
    Join Date
    Oct 2007
    Location
    IN YOUR FACE
    Posts
    341

    Re: How do you create a Comment Box? Script help please


  9. #9
    pandaxx's Avatar
    pandaxx is offline x10Hosting Member
    Join Date
    Jul 2008
    Location
    US OF A
    Posts
    28

    Re: How do you create a Comment Box? Script help please

    Quote Originally Posted by Jacob, Kid Mania Creator View Post
    It won't let me view it :<

  10. #10
    chili5's Avatar
    chili5 is offline x10Hosting Member
    Join Date
    Aug 2008
    Posts
    36

    Re: How do you create a Comment Box? Script help please

    You don't need a database to make this, but it is a whole lot easier than using text files. After reading through tutorials on w3schools, you should be able to make a PHP/MySQL/XHTML/CSS guestbook like script.

    http://www.tutorialized.com/tutorial...milies-w/35155

Page 1 of 2 12 LastLast

Similar Threads

  1. Access to 300+ PHP scripts (2500 credits)
    By jonathanyaniv in forum Classifieds
    Replies: 11
    Last Post: 06-03-2008, 10:58 PM
  2. samba server issue
    By hopper in forum Off Topic
    Replies: 2
    Last Post: 04-13-2008, 10:59 PM
  3. Replies: 8
    Last Post: 12-03-2007, 04:12 PM
  4. Create account script help
    By salukigirl in forum Scripts, 3rd Party Apps, and Programming
    Replies: 1
    Last Post: 09-20-2007, 01:17 AM
  5. Server UP time Script
    By dharmil in forum Scripts, 3rd Party Apps, and Programming
    Replies: 2
    Last Post: 04-03-2006, 04:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers