How do you create a Comment Box? Script help please

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by pandaxx, Aug 1, 2008.

  1. pandaxx

    pandaxx New Member

    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. Salvatos

    Salvatos Member Prime Account

    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. Hazirak

    Hazirak New Member

    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. marshian

    marshian New Member

    You're right, no sense in making things more complicated than they need to be -> use mysql, it's faster and easier
  5. Hazirak

    Hazirak New Member

    ... 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. woiwky

    woiwky New Member

    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/
  7. pandaxx

    pandaxx New Member

    Thanks everyone!<3
  8. pandaxx

    pandaxx New Member

    It won't let me view it :<
  9. chili5

    chili5 New Member

  10. MadameSkylark

    MadameSkylark New Member

    Blah! I really would like to add a comment area on my page as well, but I'm not savvy enough to go through the cha-cha of creating one from scratch. Are there ANY websites out there that allow you to generate a comment box that AREN'T related to Myspace?
  11. Bhagu

    Bhagu New Member

  12. ezadx10b

    ezadx10b New Member

  13. johncruz

    johncruz Banned

    You can create a comment box by using this code.

    <form action="/html/tags/html_form_tag_action.cfm" method="post">
    Comments:<br />
    <textarea name="comments" id="comments">
    Hey... say something!
    </textarea><br />
    <input type="submit" value="Submit" />
    </form>
  14. essellar

    essellar Community Advocate Community Support

    That'll work just fine if you happen to be using a server that's running ColdFusion (a proprietary Adobe platform that, well, isn't free by a long shot). If you're using Adobe's Creative Suite bundle to do local development for sites meant for free/low-cost shared web hosting, you need to stop that now. Or at least turn off the ColdFusion option. Dreamweaver does enough damage all by itself, you don't need to compound the problem by lying to it about the kind of server you'll be using.

Share This Page