2

我正在尝试限制评论和对评论的回复,并在达到限制后显示错误消息。我已成功限制评论和评论回复,并在仅提示评论而不是评论回复时成功提供了错误消息。

评论回复有一点 jquery 与他们一起工作,所以这是我能看到的唯一会导致消息不显示的事情。我尝试了其他方法,然后是当前使用的方法。

$valid = true;
$max_post_per_day = 5;
$max_reply_per_day = 5;

//THE REGULAR COMMENTS STRUCTURE THAT IS SHOWING THE ERROR MESSAGE PROPERLY

$query = "SELECT COUNT(*) FROM `cysticBlogComments`
              WHERE `userID` = $auth->id
                AND `date` = CURDATE()";
    $result = mysql_query($query, $connection);
    $post_count = mysql_result($result, 0);
    $error_msgs_max_comment[] = "Whoops! You have reached the maximum amount of comments allowed for the day.";

    if($post_count >= $max_post_per_day)
    {
        $valid = false;
    }
    else
    {

    $query = "INSERT INTO `cysticBlogComments` 
                                    ( `blogID`,
                                      `userID`,
                                      `commentBody`,
                                      `status`,
                                      `date`,
                                      `time`
                                      ) VALUES (

                                      '" . $blogID ."',
                                      '" . $auth->id ."',
                                      '" . mysql_real_escape_string($_POST['BlogComment']) ."',
                                      'active',
                                      '" . date("Y-m-d") . "',
                                      '" . date("G:i:s") . "')";


    mysql_query($query, $connection);

}

<?php if(isset($_POST['commentBlogSubmit']) && $post_count >= $max_post_per_day ) {
                foreach($error_msgs_max_comment as $msg) { ?>
                <div id="error_x">
                <?php echo $msg; ?>
                </div>
                <?php }
                }?>

//THE REPLY COMMENT STRUCTURE THAT IS LIMITING BUY NOT DISPLAYING ERROR AND HAS JQUERY WITH IT

$query = "SELECT COUNT(*) FROM `CysticBlogComments_replies`
                      WHERE `FromUserID` = $auth->id
                        AND `date` = CURDATE()";
            $result = mysql_query($query, $connection);
            $post_count = mysql_result($result, 0);
            $error_msgs_max_reply[] = "Whoops! You have reached the maximum amount of replies allowed for the day.";

            if($post_count >= $max_reply_per_day)
            {
                $valid = false;
                echo $error_msgs_max_reply;
            }
            else
            {

    $query = "INSERT INTO `CysticBlogComments_replies`
                                        ( `BlogCommentID`,
                                          `FromUserID`,
                                          `comment`,
                                          `status`,
                                          `date`,
                                          `time`
                                        ) VALUES (

                                        '" . mysql_real_escape_string($_POST['comment']) ."',
                                        '" . $auth->id ."',
                                        '" . mysql_real_escape_string($_POST['reply'])."',
                                        'active',
                                        '" . date("Y-m-d") . "',
                                        '" . date("G:i:s") . "')";

    mysql_query($query, $connection);
}

<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day ) {
                foreach($error_msgs_max_reply as $msg) { ?>
                <div id="error_x">
                <?php echo $msg; ?>
                </div>
                <?php }
                }?>

//THE JS FOR THE REPLIES

<script type="text/javascript">
        $(document).ready( function() {

            $.localScroll({ offset:{top:-40,left:0} });

            $("a.reply_link").click( function() {
                $("#"+$(this).attr('name')).fadeIn('slow');
            });

            $(".respond_nevermind a").click( function(event) {
                event.preventDefault();
                var reply_box = document.getElementById($(this).attr('href'));
                $(reply_box).css('display','none');

                var reply_textarea = document.getElementById($(this).attr('href')+"_textarea");
                $(reply_textarea).val('');
            });
        });
</script>
4

2 回答 2

5

PHP 在执行 JavaScript 之前在服务器上运行,因此两者无法交互。JavaScript可能与 PHP 生成的 HTML 存在问题(换句话说,只有一个 JavaScript 错误),或者 HTML 本身可能包含错误,例如缺少结束符>或引号。

于 2012-04-27T23:59:10.077 回答
0

看起来您在第二次通话<?php后没有正确关闭标签。mysql_query()您正在打开一个新<?php标签,但我没有看到前一个<?php标签被关闭。

于 2012-04-28T00:16:19.693 回答