Jump to content

VAT function into SESSION??


jsk1gcc

Recommended Posts

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 =)

 

//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 ;


 

$_SESSION['priceWvat']=$_POST['what do i put here?'];

 

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 =)

 

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/223895-vat-function-into-session/
Share on other sites

This is the entire code =)

 

<?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 ;


?>

 

Again messy code, what I am trying to do is add the VAT of two seats costing 3.00, The price is $price from the `ride` table.

 

hope this is a little clearer =)

 

$_POST['seat'] won't have a value before the form is submitted, therefore you can't assign its value to the $_SESSION var. Also, <option> tags don't get name= attributes, they get value= attributes, and each value should be different . . ,

of course, so sorry. of course they are used. *dunce moment* I had them at values at one point when they where single drop down boxes but they got changed along the way when I need multiple selections.

 

I used forms because I was using a tutorial as so how to create the drop down boxes. I didn't know I could live without them =) I will try that.

 

 

the aim of the system is to be able to book two or more seats next to each other. I've tried many ways and I understand that using two boxes is messy but I don't have the knowledge to be able to try another way.

anyway after you've chosen the two seats [seat] and [seat2] they get posted to the next page for confirmation, all is well there.

 

what I wanted help on was how to get the price of both seats plus VAT in a session to be posted too. I've tried different variations and I can't seem to get anywhere.

 

I hope this helps a little more, sorry if I'm being slow. I've been surviving on more coffee than sleep and I am shattered and finding it hard to see blatant errors. 0.o

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.