Jump to content

if statement not triggering


RalphLeMouf

Recommended Posts

Hello,

 

I have been banging my head against the walla and trouble shooting this for days now. It seems so simple, yet there is something going on that I can't figure out. Thanks so much in advance for the help

 

I am currently limiting comments and replies to comments on my social network. I have successfully done so except on the replies for one page, I can not get php to display an error with a simple if statement that should be firing when the submit button is hit.

 

It's important to know that I have TWO pages being used. The main structural page and then the content page that is included in the structural page.

 

Here is the code:

 

[code]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;
	$error_msgs_replies_max[] = "Whoops! You have reached your limit of replies for the day."; 




    if($post_count >= $max_reply_per_day){
			$valid = false;

    }
    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);



}

// this is from the page that is included, to echo the error but the if is not triggering
<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day && $valid = false) {


			foreach($error_msgs_replies_max as $msg) { ?>
			<div id="error_x">
			<?php echo $msg; ?>
			</div>
			<?php }
		}?>

[/code]

Link to comment
Share on other sites

Sorry. I was actually quoting this line of code:

 

<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day && $valid = false) {

I didn't realize what I had typed was a complete line of code from another part of the file. You need to change THIS line so that (I'm assuming you want):

<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day && $valid != false) {

or it may be:

<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day && $valid == false) {

Either way, the code you have now will set the $valid variable to false no matter what, and the IF statement will fail.

Link to comment
Share on other sites

My logic tells me that I want

$valid == false

because I want it to only trigger IF false. However I tried all of your suggestions and it's still not echoing. The only time I can get the message to show up is when I do

<?php if($post_count >= $max_reply_per_day ) {

wrapped around the error message. Problem is, that it shows up WHEN the page loads, not after the button is submitted. It's a triggering problem. I've

die()

all the variables and they are working properly. Its not reading

$if(isset($_POST['sub_comment_reply']))

for a trigger for some reason. Gonna go back and check that again :shrug:

Link to comment
Share on other sites

this may help as this is the code chunk that is also involved within the if statement that is NOT firing still

 

<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>

Link to comment
Share on other sites

You basically have a whole page that doesn't work. Snippets of code from that page don't really help us because the posted snippets of code are each doing what they were written to do. The problem is in something that's occurring somewhere between those snippets of code.

 

Without all the logic on the offending page that is needed to reproduce the problem, its not directly possible to help you with the logic on your offending page. I'm going to guess that you have overwritten $_POST['sub_comment_reply'] at some point between where it is set at the top of that posted code and where you test it again in the included code. The problem could even be in how you are including that code.

 

When you were dumping the values, were you doing that in the included file's code or was that in the main file's code?

 

Posting the full relevant code will be the quickest way of getting a solution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.