How to code comment box with PHP and mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chijioke
    New Member
    • May 2017
    • 4

    #1

    How to code comment box with PHP and mysql

    i am developing a comment box with php and mysql,but my problem now is how to post the comment after user has enter their comment.so far i my php and mysql that save the comment in the database,but i want it to be visible on my webpage after it is save to database,i don't know the code for that,i need help.


    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>
    commenting system
    </title>
    </head>
    <body>
     
    <form action = "cm.php" method = "POST">
    <input type = "text" name = "fname" placeholder = "Name"><br><br>
    <input type = "text" name = "website" placeholder = "website"><br><br>
    <textarea type = "text" name = "scomment" rows = "6" col = "250" placeholder = "comment here....">
    </textarea>
    <button type = "submit">SUBMIT</button>
    </form>
     
     
    </body>
    </html>
    cm.php

    Code:
    <?php
    include 'db.php';
    $fname = $_POST['fname'];
    $website = $_POST['website'];
    $scomment = $_POST['scomment'];
     
    $sql = "INSERT INTO client (fname, website, comment) VALUES ('$fname', '$website', '$scomment')";
    $result = $con->query($sql);
     
     
    header("Location:index.php");
     
    ?>
    db.php

    Code:
    <?php
    
    $con = mysqli_connect("localhost", "root", "", "comment");
    
    if(!$con){
    die("connection error".mysqli_connect_error());
    }
    Last edited by Dormilich; May 15 '17, 03:37 PM. Reason: please use code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    my problem now is how to post the comment after user has enter their comment.
    on which page do you want to display the comments?

    Comment

    • chijioke
      New Member
      • May 2017
      • 4

      #3
      now i was able to display the comment,but my problem is how to make each comment has its reply under the respective comment how can i go about this.

      Comment

      Working...