EchoFool Posted June 6, 2008 Share Posted June 6, 2008 I keep getting this error: Fatal error: Cannot break/continue 1 level in C:\xampp\htdocs\css\includes\afunctions23\functions.php on line 85 But am unsure why it means by this error? The logic of where my break is this: <?php //header include($_SERVER['DOCUMENT_ROOT'].'/css/layout1.php'); //unrelated code stuff here # # # function blank($Value){ If($Value == ''){ ?> <br><br><br> <p align="center"> <span class="NegativeMoney">Value is blank!</span><br> <br><a href="itemviewer.php">Back</a> </p> <br><br><br> <?php break; //this is the line which is related to the error } } If(isset($_GET['Edit'])){ $MissionID = mysql_real_escape_string($_GET['Edit']); blank($MissionID); } //footer include($_SERVER['DOCUMENT_ROOT'].'/css/layout2.php'); ?> Link to comment https://forums.phpfreaks.com/topic/109059-break-error-please-help/ Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 You can only 'break' out of a loop or switch case. What are you trying to accomplish? Link to comment https://forums.phpfreaks.com/topic/109059-break-error-please-help/#findComment-559494 Share on other sites More sharing options...
EchoFool Posted June 6, 2008 Author Share Posted June 6, 2008 Well say the function breaks... it will show the error : Value is blank. And the rest of the script won't run because the break comes after it. How ever i was in a dilemma as I need the footer to still be appearing when the break has occured. So i considered this in my function: <?php Echo error include($_SERVER['DOCUMENT_ROOT'].'/css/layout2.php'); break; ?> But have yet to establish what is wrong with using break in the first place yet. The other alternative was to remove the function and have this: <?php //header include($_SERVER['DOCUMENT_ROOT'].'/css/layout1.php'); If(isset($_GET['Edit'])){ $MissionID = mysql_real_escape_string($_GET['Edit']); If($Value == ''){ ?> <br><br><br> <p align="center"> <span class="NegativeMoney">Value is blank!</span><br> <br><a href="itemviewer.php">Back</a> </p> <br><br><br> <?php }Else{ //do rest of script } //footer include($_SERVER['DOCUMENT_ROOT'].'/css/layout2.php'); ?> How ever the issue with this is, I then don't use the function. Yet the function is checking a variable to see if its blank which is pretty much a check I do on any input from users so I loose the option of using a function to save time and amount of coding. What other options do i have if any? Link to comment https://forums.phpfreaks.com/topic/109059-break-error-please-help/#findComment-559519 Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 If you want to abruptly end execution of a function, simply return something... commonly, in the case of an error, you'd return FALSE <?php function reverseWord ( $word ) { # Check to see if it's only a single word if ( preg_match( '/[^\w]/', $word ) ) # It contains non-word characters, abort! return FALSE; return strrev( $word ); } $foo = 'bar!'; if ( ( $fooRev = reverseWord($foo) ) === FALSE ) echo '$foo contained bad characters!'; else echo $fooRev; ?> Link to comment https://forums.phpfreaks.com/topic/109059-break-error-please-help/#findComment-559537 Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 And if you want to know whats wrong with using break, maybe you should find out what it does http://www.php.net/break Link to comment https://forums.phpfreaks.com/topic/109059-break-error-please-help/#findComment-559539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.