VAT function into 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
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

VAT function into SESSION??

Post by jsk1gcc »

Hey, I have a VAT function that I need to carry across to the next confirmation page.
I am using sessions, but for the life of me I can't get the variable right.

I've been working all day and am pretty tired, there must be something I am missing. would love another pair of eyes on it =)

Code: Select all

<?php
//connect  include
require("connect.php");

session_start(); 
#error_reporting(E_ERROR); //turn off error for session variables
echo "your choosen ride is: " .$_SESSION ['result'];

//extract data
$extract =mysql_query("SELECT * FROM ride WHERE rideID ='3'");
$numrows = mysql_num_rows($extract);
//start of form
echo '<form method="post" name="f1" action="confirm.php">';
echo 'Please choose a seat:  '; 
echo"<select multiple name='seat' size='2'>";
		while( $row = mysql_fetch_assoc($extract)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['name'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat'> $seatNumber </option>";
			$_SESSION['extract']=$_POST['seat'];
		#	$_SESSION['result']=$_POST['ABC']; //wasc alling blank variable

		}  
echo '</select><br>'; 
?>
<?php
require('connect.php');

$extract2 =mysql_query("SELECT * FROM ride WHERE rideID ='3'");
$numrows = mysql_num_rows($extract2);
//start of form
echo '<form method="post" name="f2" action="confirm.php">';
echo 'Please choose a seat:  ';echo"<select multiple name='seat2' size='2'>"; 

		while( $row = mysql_fetch_assoc($extract2)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['name'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat2'> $seatNumber </option>";
			$_SESSION['extract2']=$_POST['seat2'];
		#	$_SESSION['result']=$_POST['ABC']; //was calling blank variable

		}  
echo '</select><br>'; 
?>
<?php
#$end =$_POST['endPrice'];
$_SESSION['priceWvat']=$_POST['endPrice'];

echo "<input type='submit' value='Submit'>";
echo "</form>";

//show time and price
echo "The price of the ride is: £$price<br>The duration if of the ride is: $time minutes<br>" ;

#$totalPrice=($_SESSION['extract']+$_SESSION['extract2']);
#echo $totalPrice;

//VAT function
$seatPrice=($price*2);
$vat=17.5;
$priceXvat=0.300;
function vat($vat, $priceXvat)
	{
		return sprintf("%01.2f", ($vat*$priceXvat/ 100));
	}
$vatprice = vat(17.5, 3.00);
$total=($vatprice*2);
$endPrice= ($total+$seatPrice);
//Ftotal
	echo "<br>";
	echo "The price including VAT is: £ ";echo $endPrice ;


?>
ps: I understand that the code is a little scruffy and not the best it could be, any help here would be great too but if not that's cool =)
what I am trying to do is add the VAT of two seats costing 3.00, The price is $price from the `ride` table. the VAT needs to go to another page and maybe further, any help?

Thanks.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: VAT function into SESSION??

Post by Neilos »

jsk1gcc wrote: Hey, I have a VAT function that I need to carry across to the next confirmation page.
What exactly are you trying to carry across?

I see a VAT function here;
jsk1gcc wrote:

Code: Select all

//VAT function
$seatPrice=($price*2);
$vat=17.5;
$priceXvat=0.300;
function vat($vat, $priceXvat)
        {
                return sprintf("%01.2f", ($vat*$priceXvat/ 100));
        }
$vatprice = vat(17.5, 3.00);
$total=($vatprice*2);
$endPrice= ($total+$seatPrice);
//Ftotal
        echo "<br>";
        echo "The price including VAT is: £ ";echo $endPrice ;
But which part are carrying across?
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

Re: VAT function into SESSION??

Post by jsk1gcc »

Neilos wrote: What exactly are you trying to carry across?
I am trying to carry the $endPrice I don't think I'm adding it right. =|

the user can pick two seats.. one from each drop down, the ride has a price $price this one is 3.00, plus vat = $endPrice. I need that end price posted to other pages for an insert script and an email script. sessions seem the best option but i can't get it to go into one.

I know I am doing it wrong but I don't know enough about sessions to assign it properly.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: VAT function into SESSION??

Post by Neilos »

Ahh ok. After you assign the value of $endPrice you can do this;

Code: Select all

$_SESSION['endPrice'] = $endprice;
But it seems you already know how to do this so I'm unsure if this is your problem. If not then please let me know.


But I think that sessions is not the best way to do it however, If you just want a form selection to be posted to the next page then using POST variables would be better in my opinion. However the session will work also.
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

Re: VAT function into SESSION??

Post by jsk1gcc »

Thankyou, It must have been a spelling mistake somewhere, yours worked . Thanks =)
Post Reply