Aureole Posted October 8, 2007 Share Posted October 8, 2007 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... ??? Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/ Share on other sites More sharing options...
haaglin Posted October 8, 2007 Share Posted October 8, 2007 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.'; } Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364655 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364660 Share on other sites More sharing options...
GamingWarrior Posted October 8, 2007 Share Posted October 8, 2007 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364666 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364669 Share on other sites More sharing options...
haaglin Posted October 8, 2007 Share Posted October 8, 2007 That would make the html part uneditable and may corrupt the code in wysiwyg editors like Dreamweaver and golive etc.. (when not in source mode) Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364670 Share on other sites More sharing options...
MmmVomit Posted October 8, 2007 Share Posted October 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364671 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 I don't care! :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. 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. Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364672 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364674 Share on other sites More sharing options...
haaglin Posted October 8, 2007 Share Posted October 8, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364678 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364684 Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 You could use a switch statment: <?php switch($val) { case 'condition': do stuff break; case 'condition2': do stuff break; case 'condition3': do stuff break; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364688 Share on other sites More sharing options...
haaglin Posted October 8, 2007 Share Posted October 8, 2007 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.. } //... ?> Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364690 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 Thanks haaglin that's what I needed. Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364739 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364745 Share on other sites More sharing options...
MmmVomit Posted October 8, 2007 Share Posted October 8, 2007 foreach($errors as $v) { echo "<p>$v</p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364748 Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 Use the implode() function: <?php if(count($errors) > 0) echo implode('<br>',$errors); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-364765 Share on other sites More sharing options...
Aureole Posted October 9, 2007 Author Share Posted October 9, 2007 Thanks, both implode() and foreach() do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/72319-solved-gah-looks-like-i-forgot-to-close-an-if-but-i-cant-find-it/#findComment-365204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.