Php Comment Box

Discussion in 'PHP' started by Funtob, Jan 29, 2013.

  1. #1
    Pls I need to create a php comment box for my site dat shows user image after dey comment and also shows guest image as avatars after dey comment on each product, like dat of dis site thanks in advance.
     
    Solved! View solution.
    Funtob, Jan 29, 2013 IP
  2. andrewhoward123

    andrewhoward123 Active Member

    Messages:
    149
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    50
    #2
    I also want to create comment box and how can i create it...
     
    andrewhoward123, Jan 29, 2013 IP
  3. mokah

    mokah Active Member

    Messages:
    88
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    65
    #3
    Hello, you'll need to set up a database with the correct amount of tables with the correct information. You are probably going to be collecting:
    • Names
    • Email Addresses
    • Website
    • Message
    The contact form should allow submission, sanitise inputted information, validate inputted information then store the information in the database. If the information does not pass all validation tests successfully, an error message should be shown to the user.

    It is fairly easy to retrieve this information from the database to display it on the page, the email address provided should also be used to search for a Gravatar, the Gravatar should be displayed if one exists, otherwise a default avatar should be displayed.
     
    mokah, Jan 29, 2013 IP
  4. Funtob

    Funtob Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    kk got you
     
    Funtob, Jan 29, 2013 IP
  5. Funtob

    Funtob Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    pls can u teach me how to do dat with php and mysql
     
    Funtob, Jan 29, 2013 IP
  6. mokah

    mokah Active Member

    Messages:
    88
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    65
    #6
    Please use the information I have provided you to do some research and learning of your own. No one is going to create this for you.
     
    mokah, Jan 29, 2013 IP
  7. #7
    Here is the skeleton of my script for comments. I have change/cut a lot of code but this is the base. You can add fields (images, etc.).

    
    <!-- this code goes in each product page -->
     
        <?php
            $username = "xxx";
            $password = "xxx";
            $db = "xxx";
            $host = "localhost";
               
            $xdb = new PDO("mysql:host=$host;dbname=$db", $username, $password);
            $xdb->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
     
            function commentlist ($productid) {
                $q = "select * from commenttable where productid like '" . $productid . "'";
           
                $query = $xdb->query($q) or die("Database problem!!");
                $query->setFetchMode(PDO::FETCH_ASSOC); 
               
                while($row = $query->fetch()) {
                    echo "<div class='poster'><div style='float:left'>" . $row["nickname"] . "</div><div style='float:right; font-weight:normal; font-size:10px'>" . date("F d, Y", strtotime($row["added"])) . "</div></div>";
                    echo "<div class='comment'>" . $row["comment"] . " </div>";
                }
            }
           
            function countComments ($productid) {
                $q = "select count(id) as count from commenttable where productid like '" . $productid . "'";
           
                $query = $xdb->query($q) or die("Database problem!!");
                $query->setFetchMode(PDO::FETCH_ASSOC); 
               
                while($row = $query->fetch()) {
                    echo $row["count"];
                }
            }
           
        ?>
     
    <div class="comment" id="comment">
    <p>Comments (<?php countComments($productid); ?>)</p>
    <div class="comments">
    <div>
        <form name="comfrm" action="comments.php" id="comfrm">
        <textarea name="comment" id="comment" placeholder="Leave a comment..."></textarea>
    </div>
    <div style="height:50px;">
        <div style="text-align:left; float:left"><input type="text" name="poster" id="poster" placeholder="Post as..." /><input name="productid" id="productid" type="hidden" value="<?php echo productID; ?>" /></div>
        <div style="float:right; margin-top:15px; margin-right:35px;"><input type="submit" name="submit" class="submit" id="submit" value="submit" /></div>
    </div>
    </form>
    </div>
    <div class="commentlist">
        <?php commentlist($productid); ?>
    </div>
    </div>
     
    <!-- end code -->
     
     
    <!-- comments.php file -->
     
    <?php
        $username = "xxx";
        $password = "xxx";
        $db = "xxx";
        $host = "localhost";
               
        $xdb = new PDO("mysql:host=$host;dbname=$db", $username, $password);
        $xdb->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
       
        $s = $xdb->exec("insert into commenttable (nickname, added, comment, productid) values ('" . $_POST['poster'] . "',DATE_FORMAT(NOW(),'%Y-%m-%d'),'" . $_POST['comment'] . "','" . $_POST['productid'] . "')");
       
        $xdb = NULL;
    ?>
     
     
    <!-- end file -->
    PHP:
    I hope that will be helpful to start. But if you don't want to mess with code you must find a full script for comments. google it and you will find something.
     
    Last edited by a moderator: Feb 4, 2013
    xxxize, Feb 4, 2013 IP
  8. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #8
    It sounds like you're a tad out of your depth here. You're either going to have to learn a language like PHP, or use something premade like Disqus.
     
    Alex Roxon, Feb 4, 2013 IP