<div class="container"> <form method="POST" id="comment_form"> <div class="form-group"> <input type="text" name="comment_name" id="comment_name" class="form- control" placeholder="Enter Name" /> </div> <div class="form-group"> <textarea name="comment_content" id="comment_content" class="form-control" placeholder="Enter Comment" rows="5"></textarea> </div> <div class="form-group"> <input type="hidden" name="comment_id" id="comment_id" value="0" /> <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit" /> </div> </form> <span id="comment_message"></span> <br /> <div id="display_comment"></div> add_comment.php <?php //add_comment.php $connect = new PDO('mysql:host=); $error = ''; $comment_name = ''; $comment_content = ''; if(empty($_POST["comment_name"])) { $error .= '<p class="text-danger">Name is required</p>'; } else { $comment_name = $_POST["comment_name"]; } if(empty($_POST["comment_content"])) { $error .= '<p class="text-danger">Comment is required</p>'; } else { $comment_content = $_POST["comment_content"]; } if($error == '') { $query = " INSERT INTO tbl_comment (parent_comment_id, comment, comment_sender_name) VALUES (:parent_comment_id, :comment, :comment_sender_name) "; $statement = $connect->prepare($query); $statement->execute( array( ':parent_comment_id' => $_POST["comment_id"], ':comment' => $comment_content, ':comment_sender_name' => $comment_name ) ); $error = '<label class="text-success">Comment Added</label>'; } $data = array( 'error' => $error ); echo json_encode($data); ?>