ghettobsd Posted March 16, 2010 Share Posted March 16, 2010 Hi, I recently upgraded php to work with mysql and something broke! I'm moving a site from a linux host to a bsd host. Everything is working out except for php! The page in question worked fine on linux php5.2.8, and bsd php5-5.2.11. But the difference in version (it happened after i updated mysql) has caused some code to not work properly. The code in question is this: $link_pt1 = '<li'; $link_pt2 = '><a href="'; $link_pt3 = '">'; $link_pt4 = '></a></li>'; While on linux host it works great, on bsd it displays: '; $link_pt4 = '>'; $link_01 = home; $link_02 = services; $link_03 = about; $link_04 = contact; $link_05 = espa Everything else is working fine (as far as php is concerned). Any ideas? The only thing I came up with is that > is messing things up. If I remove it everything just ends up being null. If I leave it in I see all that garbage! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2010 Share Posted March 16, 2010 What opening php tag is being used in the code? Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026790 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 I believe that would be : <?php Here is the top part of the file: <?php function menu(){ echo $name; global $name; $active = " class=\"current_page_item\""; $link_pt1 = '<li'; $link_pt2 = '><a href="'; $link_pt3 = '">'; $link_pt4 = '</a></li>'; $link_01 = home; $link_02 = services; $link_03 = about; $link_04 = contact; $link_05 = espanol; $link_06 = '/forum/'; $link_07 = '/blog/'; $php = ".php"; $esp = "es_pages/index"; $esu = "es_"; $enp = "en_pages/"; $enu = "en_"; $home = Home; $service = Services; $about = 'About Us'; $contact = 'Contact'; $espanol ='Español'; $forum = Forum; $blog = Blog; if ( $name == "home" ) { echo "$link_pt1$active$link_pt2$home$php$link_pt3$home$link_pt4"; } else { echo "$link_pt1$link_pt2$home$php$link_pt3$home$link_pt4"; } if ( $name == services ) { echo "$link_pt1$active$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4"; } else { echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4"; } if ( $name == about ) { echo "$link_pt1$active$link_pt2$enp$enu$link_03$php$link_pt3$about$link_pt4"; } else { echo "$link_pt1$link_pt2$enp$enu$link_03$php$link_pt3$about$link_pt4"; } if ( $name == contact ) { echo "$link_pt1$active$link_pt2$enp$enu$link_04$php$link_pt3$contact$link_pt4"; } else { echo "$link_pt1$link_pt2$enp$enu$link_04$php$link_pt3$contact$link_pt4"; } echo "$link_pt1$link_pt2$esp$php$link_pt3$espanol$link_pt4"; echo "$link_pt1$link_pt2$link_06$link_pt3$forum$link_pt4"; echo "$link_pt1$link_pt2$link_07$link_pt3$blog$link_pt4"; } ?> <?php menu();?> thanks! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026792 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 Oh, and this is the error I get: [Mon Mar 15 21:42:48 2010] [error] [client ] PHP Notice: Use of undefined constant home - assumed 'home' in /usr/local/www/apache22/website/index.php on line 3 index.php has this: <?php $name = home; require('header.php'); ?> <body> <!-- start header --> <!-- end header --> <!-- start page --> <div id="page"> <!-- start leftbar --> <div id="leftbar" class="sidebar"> Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026793 Share on other sites More sharing options...
Skepsis Posted March 16, 2010 Share Posted March 16, 2010 That is just a notice, not an actual error, try putting "home" in quotes, like: $name = 'home'; Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026796 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 When the code is like this: $name = 'home'; i don't get an error but the menu is not displayed. I should explain some more. Every page has the $name = name; code. that way I know where I'm at and the header.php can appropriately highlight the correct section name. so literally, i have : "$name = about;" on my about page, and "$name = home;" in the index.php. This works on the linux host., but not on BSD. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026798 Share on other sites More sharing options...
trq Posted March 16, 2010 Share Posted March 16, 2010 Have you got home, about, services etc etc defined as constants? Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026803 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 no, not constants, just variables. I have 7 tabs. And I want the corresponding tab to be lit up. So that would be: # Home # Services # About Us # Contact # Español # Forum # Blog and in each "page" they have " $name = page-name; " If I define a constant, would it still work? because the main page calls the header, and the header processes the name to match it up accordingly. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026825 Share on other sites More sharing options...
trq Posted March 16, 2010 Share Posted March 16, 2010 Variables must start with $ so your code is all sorts of broken. Maybe your old server had error reporting turned off but its your code that is the issue. Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026833 Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 no, not constants, just variables. I have 7 tabs. And I want the corresponding tab to be lit up. So that would be: # Home # Services # About Us # Contact # Español # Forum # Blog and in each "page" they have " $name = page-name; " If I define a constant, would it still work? because the main page calls the header, and the header processes the name to match it up accordingly. thanks! You don't need to define constants. You should be quoting your text. From what I see, you shouldn't be using globals, either. You can pass parameters to your "menu" function. I've never used PHP on BSD, but you can try modifying your echoes. For example: echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4"; to echo $link_pt1.$link_pt2.$enp.$enu.$link_02.$php.$link_pt3.$service.$link_pt4; You're only concatenating your variables (no literals,) so there's no need for quotes. Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1026836 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 haha yeah, it's not pretty but it works! Well, it works on different php version! What's weird is that it worked fine when I initially installed apahe 2.2 and php5, but once I installed mysql everything went sideways. I've gotten rid of (by correcting) all other messages (whether they ere errors or notices). It's just this that remains. Variables must start with $ so your code is all sorts of broken. Maybe your old server had error reporting turned off but its your code that is the issue. If you refer to where it shows "# home # services etc" that's now how the code is (it's displayed in a php post earlier). If you refer to something else, how is it f'ed up lol thanks. You don't need to define constants. You should be quoting your text. From what I see, you shouldn't be using globals, either. You can pass parameters to your "menu" function. I've never used PHP on BSD, but you can try modifying your echoes. For example: echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4"; to echo $link_pt1.$link_pt2.$enp.$enu.$link_02.$php.$link_pt3.$service.$link_pt4; You're only concatenating your variables (no literals,) so there's no need for quotes. Ok I'll try that out and report how it works out. Thanks for the help ma! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1027054 Share on other sites More sharing options...
nafetski Posted March 16, 2010 Share Posted March 16, 2010 Oh god I promise there is a better way to do all of this Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1027083 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 OK, so I started going through the code to make the changes and I added 's to $name = 'page'; Then I decided to go from bottom up. That's when I saw this: <? menu();?> And would you believe that once i changed that to: <?php menu(); ?> made all the difference in the world? haha So now it's working again. Apparently the previous version didn't complain about not having ?php yet it worked. So I fixed it in both english and spanish versions and they both work! Thanks for all your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1027092 Share on other sites More sharing options...
ghettobsd Posted March 16, 2010 Author Share Posted March 16, 2010 Oh god I promise there is a better way to do all of this haha, point in the right direction and I'll do some reading! thanks again for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/195393-need-help-with-php5-code/#findComment-1027094 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.