Solved

passing variable to a second page

Posted on 2009-07-16
10
265 Views
Last Modified: 2012-05-07
Hi Experts
i have this in my script (page1.php)
$vat=21.5;
$taux=($amount*$vat)/100;
$taux is a variable
$amount is a result of sum from select clause
and i am using session
my problem i have page2.php second script that prints me a report but the $taux is passing as 0
then the calcul is false as the $taux is set to 0 and in my first page the calcul is perfect.
Regards
A.S
0
Comment
Question by:asaidi
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 6

Accepted Solution

by:
twocandles earned 300 total points
ID: 24868988
how do you pass the value to the second page?

do you use something like...

page1.php:

$_SESSION['myVar'] = $aux;

page2.php:

$aux = $_SESSION['myVar'];
0
 
LVL 14

Assisted Solution

by:profya
profya earned 200 total points
ID: 24869032
In $taux=($amount*$vat)/100;
if $amount is 0 then $taux is 0 too. Please check $amount variable first.
Then you can take the $taux in a session
session_start();
$_SESSION['taux']=$taux;
0
 

Author Comment

by:asaidi
ID: 24869114
Hi
sorry profya
no $taux is not set to zero i can see the total and it is right but when i send this taux to second page it is set to empty
0
 

Author Comment

by:asaidi
ID: 24869130
Hi twocandles

$_SESSION['myVar'] = $aux;
 and what is myvar set to ?
0
 
LVL 14

Expert Comment

by:profya
ID: 24869192
Ok.

Page1:
session_start();
$_SESSION['taux']=$taux;



Page2:
session_start();
$taux=$_SESSION['taux'];
echo $taux;
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:profya
ID: 24869204
Your variable will not return 0 unless it does not take the value saved in the session, there is some code assigns it to 0.
0
 
LVL 6

Assisted Solution

by:twocandles
twocandles earned 300 total points
ID: 24869332
$_SESSION['myVar'] = $taux;

 $_SESSION is a string based array, so 'myVar' is the index you use to store your value. You can call it whatever you want, for example

$_SESSION['calculatedValue'] = $aux;

as long as you use this very same index to retrieve the value from $_SESSION in another (or the same) page.
 
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 24869412
twocandles' first question was probably the most important one and I don't see it answered yet. Before you guys get carried away with using sessions to carry currency amounts (ESPECIALLY on what sounds like a shopping cart), it would be better to find out how a user goes from page 1 to page 2.

Is there a form on page 1 that submits and sends the user to page 2? Can you, asaidi, show us the full code of the page where $taux is calculated and maybe the full code for page 2?

This sounds like a situation where a specific value should be carried from page 1 to page 2 via a form, and then have page 2 calculate the tax. A lot of shopping carts calculate tax when you're shopping for individual items, so if the tax variable is in a session, it could be calculated for an individual item on one page, and then the user makes a huge checkout on another page which uses the last-calculated tax, which could be WAY off. It's usually never a good idea to store checkout amounts (of any kind - tax, shipping, etc) in a session variable. There are just too many potential exceptions.
0
 

Author Comment

by:asaidi
ID: 24873137
Hi All

really i did all these examples thanks very much but still did not work for me
the taux in the first page is working fine but when i click to go to the second page it is not the calcul is wrong and the value of taux is empty
0
 
LVL 14

Expert Comment

by:profya
ID: 24885425
Hi,
To better trance where is the problem, I do use echo statements, I write an echo statement in a place I want to make sure that things are fine until this point. In your case, variables are sent between pages either by forms, or putting your variables in a session container. Unless you gave us the entire code I would be hard to figure out what's the exact problem.
In addition to all that, we will stay beside you until your problem is solved. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now