Author Topic: Need help with PHP5 code  (Read 173 times)

0 Members and 1 Guest are viewing this topic.

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Need help with PHP5 code
« on: March 16, 2010, 12:25:51 AM »
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:

Quote
$link_pt1 = '<li';
$link_pt2 = '><a href="';
$link_pt3 = '">';
$link_pt4 = '></a></li>';


While on linux host it works great, on bsd it displays:

Quote
'; $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!

Offline PFMaBiSmAd

  • PHPFreaks Recommended
  • Freak!
  • *
    • View Profile
Re: Need help with PHP5 code
« Reply #1 on: March 16, 2010, 12:29:28 AM »
What opening php tag is being used in the code?
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #2 on: March 16, 2010, 12:41:26 AM »
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!
« Last Edit: March 16, 2010, 12:42:00 AM by ghettobsd »

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #3 on: March 16, 2010, 12:44:08 AM »
Oh, and this is the error I get:

Quote
[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">

Offline Skepsis

  • Irregular
  • Gender: Male
    • View Profile
Re: Need help with PHP5 code
« Reply #4 on: March 16, 2010, 12:54:10 AM »
That is just a notice, not an actual error, try putting "home" in quotes, like:

$name = 'home';

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #5 on: March 16, 2010, 01:01:32 AM »
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!
« Last Edit: March 16, 2010, 01:05:02 AM by ghettobsd »

Online thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
    • View Profile
Re: Need help with PHP5 code
« Reply #6 on: March 16, 2010, 01:09:11 AM »
Have you got home, about, services etc etc defined as constants?

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #7 on: March 16, 2010, 02:16:23 AM »
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!

Online thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
    • View Profile
Re: Need help with PHP5 code
« Reply #8 on: March 16, 2010, 02:59:08 AM »
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.

Offline fr34k

  • Irregular
  • Gender: Male
  • Textbook case for Sigmund Freud
    • View Profile
Re: Need help with PHP5 code
« Reply #9 on: March 16, 2010, 03:01:44 AM »
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.

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #10 on: March 16, 2010, 12:34:23 PM »
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!

Offline nafetski

  • Enthusiast
    • View Profile
Re: Need help with PHP5 code
« Reply #11 on: March 16, 2010, 01:09:29 PM »
Oh god I promise there is a better way to do all of this :P
Dev Environment: Mac - OSX Snow Leopard / Eclipse / Kohana PHP Framework
Job: Sr Software Developer: (Large scale enterprise)
Notice:  Most of my forum posts I write on my iPhone while taking a dump.  This means that I don't test most of my code, and I might sound like I'm impatient...really I'm just busy punching a grumpy
Also: I've hit Google so many times it's asking for a divorce

Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #12 on: March 16, 2010, 01:18:51 PM »
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!


Offline ghettobsdTopic starter

  • Irregular
    • View Profile
Re: Need help with PHP5 code
« Reply #13 on: March 16, 2010, 01:20:50 PM »
Oh god I promise there is a better way to do all of this :P


haha, point in the right direction and I'll do some reading!

thanks again for all your help!

« Last Edit: March 16, 2010, 01:22:22 PM by ghettobsd »

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.