Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

Variables and PHP includes problem

Hi all,

I have an issue with php includes..

On page A I have:

$id = 1;
include ('pageB.php');

then in page B I've got:

echo $id;

But it's returning nothing ...I though includes where like having a page inside a page right?

Thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Your thinking is correct, but your example does not include all the code to recreate the failure.  It is an issue of variable scope.  Look for functions or classes.
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And add

include('pageA');

in pageB
Please, keep only my last comment: global is for other things...
Conceptually what you say is correct, so there must be some minor discrepancy.  Show the full code.  

Also doublecheck that you are getting to the right page, by changing Page B to

echo "Debug 1 $id";
I wrote only stupid things: maybe I have to sleep ;-)
If you create two simple scripts doing what you say, they works, so the problem must reside in other code you have in your actual files: post your full code to get help.

Cheers
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial