如何为我的评论框添加简单的编辑器

时间:2017-02-13 09:13:49

标签: php html

大家好, 我是php新手,添加新内容,我需要帮助

为我的添加评论框添加简单的编辑器?

谢谢,我希望我能在这里得到帮助。 谢谢,我希望我能在这里得到帮助。

像这样 enter image description here

<!-- Start Add Comment -->
<?php 
if (isset($_SESSION['user'])) {
    $stopitem = $con->prepare("SELECT opitem FROM items");
    // Execute The Statement
    $stopitem->execute();
    // Assign To Variable
    $opitem = $stopitem->fetch();
    if ($opitem['opitem'] == 0) {
        ?>
        <div class="row">
            <div class="col-md-offset-1">
                <div class="add-comment">
                    <h3>
                        Add Your Comment
                    </h3>
                    <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] . '?itemid=' . $item['Item_ID'] ?>">
                        <textarea name="comment" required="required"></textarea>
                        <input class="btn btn-primary" type="submit" value="Add Comment" name="">
                    </form>
                    <?PHP
                    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                        $comment   = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
                        $userid  = $item['Member_ID'];
                        $itemid  = $item['Item_ID'];
                        if (!empty($comment)) {
                            $stmt = $con->prepare("INSERT INTO comments(comment, status, comment_date, item_id, user_id) VALUE(:zcomment, 0, NOW(), :zitemid, :zuserid)");
                            $stmt->execute(array(
                                'zcomment' => $comment,
                                'zitemid' => $itemid,
                                'zuserid' => $userid
                            ));
                            if ($stmt) {
                                echo "Comment Added";
                            }
                        } else {
                            echo '<div class="alert alert-danger">You Must Add Comment</div>';
                            echo '<script language="javascript">';
                            echo 'alert("You Must Add Comment")';
                            echo '</script>';
                        }
                    }
                        ?>
                </div>
            </div>
        </div>
        <?php
    } else {
        echo "This Item is closed."; 
    } 
} else {
    echo '<a href="login.php">Regester</a> or <a href="login.php">Log In</a> To Add Comment';
}
?>
<!-- End Add Comment -->  

1 个答案:

答案 0 :(得分:1)

只需将此添加到您的头部。

<script src="http://cloud.tinymce.com/stable/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>