-1

这几乎是我已经问过的问题的更新版本。我很确定它的 j-query 我没有干扰。由于某种原因,我在这种情况下的 if 语句没有按应有的方式触发。长话短说:我可以限制回复,但无法显示错误消息。

一些 if 的工作,我一定会指出一个不是。

提前致谢。

这是有效的:

if(isset($_POST['sub_comment_reply'])) {
    if($_POST['reply'] == "" ) {
    $valid = false;
    $error_msgs_reply[] = "Whoops! You forgot to write your reply.";
    }else{

        $query = "SELECT COUNT(*) FROM `CysticAnswers_replies`
                  WHERE `FromUserID` = $auth->id
                    AND `date` = CURDATE()";
        $result = mysql_query($query, $connection);
        $post_count = mysql_result($result, 0);
        $max_reply_per_day = 5;




        //Debugging lines
        echo "Query: {$query}<br>\n";
        echo "Post count for user id {$auth->id} is {$post_count}<br>\n";

        if($post_count >= $max_reply_per_day){
                $valid = false;
                $error_msgs_replies_max[] = "Whoops! You have reached your limit of answers for the day.";
        }
        else
        {
        $query = "INSERT INTO `CysticAnswers_replies`
                                            ( `QuestionCommentID`,
                                              `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_replies_max as $msg) { ?>
    <div id="error_x">
    <?php echo $msg; ?>
    </div>
    <?php }
?>

<?php } ?>
                <a name='reply_form_<?php echo $result['id']; ?>' style="clear:both"></a>
                <div id='reply_to_<?php echo $result['id']; ?>' class="respond_structure_future" <?php if(isset($_GET['reply_to']) && $_GET['reply_to'] == $result['id']) { echo 'style="display:block;"';}else{ echo 'style="display:none;"';} ?>>
                    <div class="respond_polaroid_future">
                        <a href="http://www.cysticlife.org/Profile.php?id=<?php echo $auth->id; ?>">
                            <img src="<?php echo $auth->img('mini'); ?>" />
                        </a>
                    </div>                              
                    <form name='comment_reply' action='<?php echo $_SERVER['REQUEST_URI']; ?>' method='post'>
                        <div class="respond_body_future round_10px">
                            <div class="respond_arrow_future"></div>
                            <div class="respond_tail_future"></div>
                            <div class="respond_data_future">
                                <textarea id="reply_to_<?php echo $result['id']; ?>_textarea" name='reply'></textarea><br />
                                <input type='hidden' name='comment' value='<?php echo $result['id']; ?>' />
                                <div class="respond_nevermind">
                                    <a href="reply_to_<?php echo $result['id']; ?>">nevermind</a>
                                </div>
                                <input type='submit' class="submit" name='sub_comment_reply' value='Reply' />
                            </div>
                        </div>
                    </form>
                </div>

        <?php } ?>
4

2 回答 2

3

你有没有尝试过:

if (isset($error_msgs_replies_max)) foreach($error_msgs_replies_max as $msg) {
  // Do stuff
} else print 'No variable $error_msgs_replies_max';

?

于 2012-05-07T16:38:01.097 回答
0

这也是错误的,你同时使用两者$error_msgs_replies_max$error_msgs_reply捕获错误..请只使用一个,例如$error_msgs_reply

你也可以更换

   foreach($error_msgs_replies_max as $msg) { ?>

foreach ($error_msgs_reply as $msg)
于 2012-05-07T16:40:25.557 回答