这几乎是我已经问过的question的更新版本。我很确定我的j查询不会干扰。出于某种原因,我在这种情况下的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 } ?>
答案 0 :(得分:3)
你试过了吗?
if (isset($error_msgs_replies_max)) foreach($error_msgs_replies_max as $msg) {
// Do stuff
} else print 'No variable $error_msgs_replies_max';
答案 1 :(得分:0)
您同时使用$error_msgs_replies_max
和$error_msgs_reply
来捕捉错误也是错误的...请仅使用一个$error_msgs_reply
您也可以替换
foreach($error_msgs_replies_max as $msg) { ?>
带
foreach ($error_msgs_reply as $msg)