View Full Version : PHP Fatal error: Cannot break/continue 1 level in
I have placed a ticket on this matter and am checking double places for a possible solution.
error_log in public_html shows:
PHP Fatal error: Cannot break/continue 1 level in /home1/useraccount/public_html/maps.php on line 481
Code shows:
<?php
chooseMap($key);
function chooseMap($key) {
if ($key == 'bentonHS') {
include ('maps/bentonHS.php');
break;
}
I have a long list of these references. All the code has to do with google maps, but was coded not given by google maps. Does anyone have any clue as to why I would get the fatal error? It only strikes me as odd because I do not get the error on my local test machine, but when I upload to the site I get the error. Any help would be appreciated and thanks in advance!
felgall
10-26-2009, 02:15 PM
You are not inside a loop or select statement and so cannot break out of the loop or select that you are not in.
Try replacing break with return. You can break out of a function by calling return.
Well it just messes it up and displays my footer twice with the second one white all across, in other words the code just looks messed up. Any reason this would display on my test server fine and change when I put it on the bluehost site (besides my test server being windows based..)?
Furthur into the code this is more of it:
if ($key == 'bentonHS') {
include ('maps/bentonHS.php');
return;
}
if ($key == 'mainoffice') {
include ('maps/mainoffice.php');
break;
}
if ($key == 'bentonwx') {
include ('maps/bentonwx.php');
break;
}
if ($key == 'shannonHS') {
include ('maps/shannonHS.php');
break;
}
and thats what each one looks like for a total of about 40 or so. Maybe I am doing something wrong? I am not an expert php programmer by any means, just learning as I go along..
felgall
10-26-2009, 02:58 PM
That code would probably work better as a select rather than all the if statements.
switch ($key) {
case 'bentonHS' : include ('maps/bentonHS.php');
break;
case 'mainoffice': include ('maps/mainoffice.php');
break;
case 'bentonwx': include ('maps/bentonwx.php');
break;
...
}
What is in the includes may also affect things.
Thanks, I got it to work by removing the additional stuff out of the included file. I am going to try reprogramming your way and see if I still would need to remove it or if I can leave it and I will have a result for you tomorrow. Thank you for the help!
Alright after changing all 41 it works just fine and it even looks a little cleaner. Now the problem I face is that my include does not work anymore. Here is the code at the end I have having a problem with:
case 'bentoncadc': include ('maps/bentoncadc.php');
break;
}
}
include ('maps/mainmap.php');
I have to have that map in there for the case that someone does not call on one of the specific locations it displays the map of all the locations, but that is a problem I am facing and for some reason for another it does not want to work. I can move it around or add its own PHP tag and it will dominate the selected key for the target area so maps.php?id=bentoncadc displays exactly what maps.php would display. I will work on it but would appreciate any help you could give, unfortunately BlueHost support scripting said it was fixed when they took a look at it, but they obviously did not know what the problem was because it was not fixed. Thanks in advance.
**Solution Below**
I moved it to the top of the code here:
<?php
chooseMap($key);
function chooseMap($key) {
include ('maps/mainmap.php');
switch ($key) {
case 'bentonHS': include ('maps/bentonHS.php');
break;
That seemed to fix the problem, and unfortunately the items contained in the included file are a bother so I have to remove those. Pooee ohh well, thank you for helping me clean up the code I appreciate the help much!
felgall
10-27-2009, 12:15 PM
case 'bentoncadc': include ('maps/bentoncadc.php');
break;
default: include ('maps/mainmap.php');
}
Yea I tried even that, I tried it everywhere with those brackets and it seemed that it would dominate all of the maps and not change the $key so after I put it there it worked right with no fatal error, thanks for the cleaner code setup and the help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.