Jump to content

break error please help


EchoFool

Recommended Posts

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

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?

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;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.