Passing variable to another pg w/o GET, POST or SESSION ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Passing variable to another pg w/o GET, POST or SESSION ??

Post by diseman »

Hello Experts,

My level = beginner

I performed some simple math equations based on my form input. Basically, all I did was assign a variable to a few monthly bills, which I added and totaled. On another page, I wanted to use this variable I created in part of another calculation I was doing on that page. I currently am using SESSION to pass it over, but that doesn't work well because I have to view the first page first before viewing the second page or the variable doesn't get passed over. In fact, I get an error message until I visit the first page...

Here's what I'm doing as an example:

income page:

Code: Select all

$monthly_income = ($gross_pay + $commission) ;
Expense Page:

Code: Select all

 $monthly_expenses = ($electricity + $water + $mortgage) ; 
One additional calculation on the Expense Page:

Code: Select all

$My_disposable_income = ($monthly_income - $monthly_expenses);
Notice in the code box directly above - the $monthly_income is from another page. How do I get $monthly_income to work on the expense page?

Seems a lot of people ask this question, but everything I found was offering up GET, POST, & SESSIONS, which don't apply in my application.

I hope I've explained it well enough for you to understand.

Thank you in advance for any help...
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by AbraCadaver »

Yes, sessions or post does apply in your case. How do you get from income page to expense page?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by diseman »

Hi,

When I login, I'm taken to a central page. From there, I have INCOME and EXPENSE links on the left. I have about 10 links on the left that I can go into at any time. Yes, I can go from INCOME to EXPENSE, but it's not always the case that I would do that or want to. In fact, I may just want to go to the EXPENSE page and then logout.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by AbraCadaver »

Sounds like you need to store this stuff in a database so that when you come back the data will be available.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by diseman »

Yeah, I've thought of that as well, but it doesn't appear to me that that's the best way. I'm not saying I know how, but it just seems like there has to be a better way.

Anyone else want to weigh in?

Thanks...
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by shawngoldw »

database. Listen to the other Shawn


Shawn
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Passing variable to another pg w/o GET, POST or SESSION

Post by diseman »

Still doesn't seem right to have to create extra database fields and then store calculations in there and then pull them on another page.

What I ended up doing was taking the calculations I wanted and put them in a separate .php page. I then INCLUDE (); the calculations on the page I need them and it works fine.
Post Reply