Jump to content

[SOLVED] Gah! Looks like I forgot to close an if but I can't find it...


Aureole

Recommended Posts

I've been searching for like half an Hour and I just can't find it...

 

I'm getting an unexpected $end error... I used Dreamweaver's Find feature and sure enough there's 29 "{" and only 28 "}" (I think those numbers are right) but I just can't find it! Please help, this is driving me insane...

 

<?php
session_start();

include('functions.swr3');

dbConnect();

$current_timestamp = time();
$errors = '';

if(userLogged()) {
if(isset($_POST['sent'])) {
        if(isset($_GET['id'])) {
		if(is_numeric($_GET['id'])) {
			if(isset($_GET['mode'])) {
				$query ="SELECT * FROM replies RIGHT JOIN forums ON forums.forum_id = replies.reply_parent_id WHERE reply_id='{$_GET['id']}' ";
				$result = mysql_query($query) or die(mysql_error());
				while($row = mysql_fetch_assoc($result)) {
					$f_flood_delay = $row['forum_flood_delay'];
					$f_min_chars = $row['forum_minimum_chars'];
				}
				$query = "SELECT * FROM `replies` WHERE reply_parent_id='".$_GET['id']."' ORDER BY `reply_id` DESC LIMIT 1";
				$result = mysql_query($query) or die(mysql_error());
				while($row = mysql_fetch_assoc($result)) {
					$lp_timestamp = $row['reply_timestamp'];
					$lp_author_id = $row['author_id'];
				}
			    if(strlen($_POST['content'] > $f_min_chars)) {
				    $r_title = mysql_real_escape_string(addslashes($_POST['title']));
					$r_content = mysql_real_escape_string(addslashes($_POST['content']));
					$r_author_id = $_SESSION['mem_id'];
					$r_author = $_SESSION['mem_dname'];
					if($_GET['mode'] == 'fast') {
						if($_SESSION['mem_id'] == $lp_author_id) {
						$lp_time_offset = $r_timestamp - $c_timestamp;
						if($f_flood_delay < $lp_time_offset) {
							$errors = 'none';
						} else {
							$errors .= 'Flood control is currently enabled. You must wait '.$f_flood_delay.' seconds after posting before you can post again.\n';
						}
					} elseif($_GET['mode'] == 'advanced') {
						// advanced reply
					} else {
						$errors .= 'Invalid string passed to mode parameter.';
					}
				} else {
					$errors .= 'Your post must consist of at least 10 characters.\n';
				}
			} else {
				$errors .= 'No mode parameter in url.\n';
			}
		} else {
		    $errors .= 'The id you supplied is not numeric.\n';
		}
	} else {
	    $errors .= 'No id specified.\n';
	}
} else {
    $errors = 'You may not access this file directly.\n';
}
} else {
    $errors .= 'You are not signed in.\n';
}

if($errors == 'none') {
$query = "INSERT INTO `replies` (reply_title, reply_content, reply_parent_id, reply_author, reply_author_id, reply_visible, reply_timestamp) VALUES ('{$r_title}', '{$r_content}', '{$_GET['id']}', '{$_SESSION['mem_dname']}', '{$_SESSION['mem_id']}', '1', '{$r_timestamp}')";
$result = mysql_query($query) or die(mysql_error());
updatePostCount($_SESSION['mem_id']);
header('Location: viewtopic.swr3?id='.$_GET['id'].'');
} else {
include('inc/header.swr3');
?>

    <div id="inner">

	<div class="con_1_outer">

	<div class="con_1_title"><h1>Error</h1></div>

		<div class="con_1_inner">

            <p class="content"><strong>We detected the following errors:</strong></p>
            <p class="content"><?php echo $errors; ?></p>

            </div>

        </div>

    </div>

<?php
include(inc/footer.swr3);
}
?>

 

EDIT:

 

Damn forums naffed up my indentation... ???

Link to comment
Share on other sites

This one is missing a "}"

if($_SESSION['mem_id'] == $lp_author_id) {

 

if($_GET['mode'] == 'fast') {
if($_SESSION['mem_id'] == $lp_author_id) {
	$lp_time_offset = $r_timestamp - $c_timestamp;
	if($f_flood_delay < $lp_time_offset) {
		$errors = 'none';
	} else {
		$errors .= 'Flood control is currently enabled. You must wait '.$f_flood_delay.' seconds after posting before you can post again.\n';
	}
        } //<----   This was missing
} elseif($_GET['mode'] == 'advanced') {
// advanced reply
} else {
$errors .= 'Invalid string passed to mode parameter.';
}

Link to comment
Share on other sites

Ah yes I see, now that I've fixed that I have a few more problems though...

 

Firstly if there are errors only one shows... why's that? Do I need to make some kind of array for my errors or something? If so how do I do it...

 

Secondly a lot of it doesn't seem to be working like the error checking but it should be as everything has been double, triple, quadruple checked... anyone see any obvious problems?

Link to comment
Share on other sites

while this isn't a must i would change

} else {
include('inc/header.swr3');
?>

    <div id="inner">

	<div class="con_1_outer">

	<div class="con_1_title"><h1>Error</h1></div>

		<div class="con_1_inner">

            <p class="content"><strong>We detected the following errors:</strong></p>
            <p class="content"><?php echo $errors; ?></p>

            </div>

        </div>

    </div>

<?php
include(inc/footer.swr3);
}
?>

TO

} else {
include('inc/header.swr3');

echo '
    <div id="inner">

	<div class="con_1_outer">

	<div class="con_1_title"><h1>Error</h1></div>

		<div class="con_1_inner">

            <p class="content"><strong>We detected the following errors:</strong></p>
            <p class="content">' . echo $errors; . '</p>

            </div>

        </div>

    </div>
';

include(inc/footer.swr3);
}
?>

Link to comment
Share on other sites

How does that help in any way shape or form? Breaking out of php mode to echo large blocks of html is to me a better way than echoing... both ways work and everyone has their own way of doing it, but that really had no relevance at all... Thanks for your seemingly random input.  ??? ??? :D :D

Link to comment
Share on other sites

Ah yes I see, now that I've fixed that I have a few more problems though...

 

Firstly if there are errors only one shows... why's that? Do I need to make some kind of array for my errors or something? If so how do I do it...

 

If PHP encounters a fatal error, it will simply quit.  Something like an undefined variable will just make the interpreter complain, and it will keep on processing the script, but there's a missing semicolon, the script will quit right there and not find errors further on in the script.

Link to comment
Share on other sites

I don't care! :D :D Someone go create a Poll "Break out of php mode or echo?", I'll come and join you once I've got my problems sorted. ;D

 

I know you're just trying to help but...

 

If PHP encounters a fatal error, it will simply quit.  Something like an undefined variable will just make the interpreter complain, and it will keep on processing the script, but there's a missing semicolon, the script will quit right there and not find errors further on in the script.

 

Well I'm not getting any errors whatsoever but I'll look for this damned missing semi-colon, thanks.

Link to comment
Share on other sites

My code is now... this:

 

<?php
session_start();

include('functions.swr3');

dbConnect();

$current_timestamp = time();
$errors = '';

if(userLogged()) {
if(isset($_POST['sent'])) {
        if(isset($_GET['id'])) {
		if(is_numeric($_GET['id'])) {
			if(isset($_GET['mode'])) {
				$query ="SELECT * FROM replies RIGHT JOIN forums ON forums.forum_id = replies.reply_parent_id WHERE reply_id='{$_GET['id']}' ";
				$result = mysql_query($query) or die(mysql_error());
				while($row = mysql_fetch_assoc($result)) {
					$f_flood_delay = $row['forum_flood_delay'];
					$f_min_chars = $row['forum_minimum_chars'];
				}
				$query = "SELECT * FROM `replies` WHERE reply_parent_id='".$_GET['id']."' ORDER BY `reply_id` DESC LIMIT 1";
				$result = mysql_query($query) or die(mysql_error());
				while($row = mysql_fetch_assoc($result)) {
					$lp_timestamp = $row['reply_timestamp'];
					$lp_author_id = $row['author_id'];
				}
			    if(strlen($_POST['content'] > $f_min_chars)) {
				    $r_title = mysql_real_escape_string(addslashes($_POST['title']));
					$r_content = mysql_real_escape_string(addslashes($_POST['content']));
					$r_author_id = $_SESSION['mem_id'];
					$r_author = $_SESSION['mem_dname'];
					if($_GET['mode'] == 'fast') {
						if($_SESSION['mem_id'] == $lp_author_id) {
							$lp_time_offset = $r_timestamp - $c_timestamp;
							if($f_flood_delay < $lp_time_offset) {
								$errors = 'none';
							} else {
								$errors .= 'Flood control is enabled. You must wait '.$f_flood_delay.' seconds after posting before you can post again.<br />';
							}
						} else {
						    $errors = 'none';
						}
					} elseif($_GET['mode'] == 'advanced') {
						// advanced reply
					} else {
						$errors .= 'Invalid string passed to mode parameter.';
					}
				} else {
					$errors .= 'Your post must consist of at least 10 characters.<br />';
				}
			} else {
				$errors .= 'No mode parameter in url.<br />';
			}
		} else {
		    $errors .= 'The id you supplied is not numeric.<br />';
		}
	} else {
	    $errors .= 'No id specified.<br />';
	}
} else {
    $errors .= 'You may not access this file directly.<br />';
}
} else {
    $errors .= 'You are not signed in.<br />';
}

if($errors == 'none') {
$query = "INSERT INTO `replies` (reply_title, reply_content, reply_parent_id, reply_author, reply_author_id, reply_visible, reply_timestamp) VALUES ('{$r_title}', '{$r_content}', '{$_GET['id']}', '{$_SESSION['mem_dname']}', '{$_SESSION['mem_id']}', '1', '{$r_timestamp}')";
$result = mysql_query($query) or die(mysql_error());
updatePostCount($_SESSION['mem_id']);
header('Location: viewtopic.swr3?id='.$_GET['id'].'');
} else {
include('inc/header.swr3');
?>

    <div id="inner">

	<div class="con_1_outer">

	<div class="con_1_title"><h1>Error</h1></div>

		<div class="con_1_inner">

            <p class="content"><strong>We detected the following errors:</strong></p>
            <p class="content"><?php echo $errors; ?></p>

            </div>

        </div>

    </div>

<?php
include('inc/footer.swr3');
}
?>

 

No errors, no missing semi-colons... the only part of the error checking that seems to work is the if(isset($_POST['sent'])) ...part.

 

I bet it's something to do with how I've coded it and not exactly an error... anyone spot anything?

Link to comment
Share on other sites

That is how an if statement works.. you have this statement:

 

if(isset($_POST['sent'])) {
   // then execute the code inside
else {
// then execute this code instead
}

 

all your IF statements is inside the other, so if one fails, it wont check for the others..

Link to comment
Share on other sites

Ah ok so is there any way I can change this without breaking up every single one of my if statements into...

 

<?php

if(condition) {
// Do stuff.
}

if(condition2) {
// Do other stuff.
}

if(condition3) {
// Do more stuff.
}

//...
?>

 

Eww, that's ugly as hell... is there no other way?

Link to comment
Share on other sites

If you want all the errors to be shown, this would be the way to do it. This is a way to execute code only if no error is found:

<?php
$errors = Array();
if(!condition) {
$errors[] = "Error in condition 1"
}

if(!condition2) {
$errors[] = "Error in condition 2"
}

if(!condition3) {
$errors[] = "Error in condition 3"
}
if(count($errors) > 0) {
   print_r($errors);
}
else {
//no errors.. execute code.. 
}
//...
?>

Link to comment
Share on other sites

Wait print_r shows like this (for example):

 

Array ( [0] => You may not access this file directly.

[1] => No id paramater.

[2] => The id you supplied is not numeric.

[3] => No mode parameter found.

[4] => You didn't enter a post!

)

 

How can I make it show like this:

 

You may not access this file directly.

No id paramater.

The id you supplied is not numeric.

No mode parameter found.

You didn't enter a post!

 

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.