Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Re: Import variable from one php file to another

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Re: Import variable from one php file to another

Postby linuxsoft » Wed Mar 06, 2013 5:26 pm

Hi,

I don't know what i am doing wrong. I have two php files, Page1.php has a summation ($Profit 2012) and i want to import the result of that variable into a Page2.php.


Page1.php

<?PHP

$Gain2012 = 500;
$Loss2012 = 200;
$Profit2012 = $Gain2012 - $Loss2012;

?>



Page2.php

<?PHP

$Profit2012 = ob_start(); include 'Page1.php'; ob_end_clean(); $Profit;

$Gain2013 = 100;
$Loss2013 = 50;
$Profit2013 = $Gain2013 - $Loss2013;
$ProfitSum = $Profit2012 + $Profit2013;

?>

As output for $Profit2012 in Page2.php, i get the data 1 instead of 300.
User avatar
linuxsoft
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Mar 06, 2013 5:17 pm

Re: Import variable from one php file to another

Postby aravindoptimus » Thu Mar 07, 2013 3:32 am

I used your code and it works fine. :D

But I tried to find why you got "1" as out put then I realized that you didn't kept the file "Page1.php" in the same folder where you kept "Page2.php". 8)
User avatar
aravindoptimus
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 07, 2013 2:00 am

Re: Import variable from one php file to another

Postby linuxsoft » Thu Mar 07, 2013 6:08 am

Thanks alot, i just find out why i had an issue.

Regards.
User avatar
linuxsoft
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Mar 06, 2013 5:17 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron