jsk1gcc Posted January 9, 2011 Share Posted January 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/ Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 What value are you trying to put into the $_SESSION var? You'd just assign it like any other variable. Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157124 Share on other sites More sharing options...
jsk1gcc Posted January 9, 2011 Author Share Posted January 9, 2011 endPrice but when I use this, it comes up with Notice: Undefined index: Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157126 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 When you use what[/] it throws that notice? Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157130 Share on other sites More sharing options...
jsk1gcc Posted January 9, 2011 Author Share Posted January 9, 2011 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157149 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 $_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 . . , Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157152 Share on other sites More sharing options...
jsk1gcc Posted January 9, 2011 Author Share Posted January 9, 2011 That's weird, they work, I can call the seat variable and it comes, no problem. I didn't know about the form values, I will change them, But will it make any difference? I am not calling them in any other page. =) Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157155 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 If the values aren't used anywhere, then why even have the form field? Your explanation of what you need to happen in that code isn't very clear, I'm afraid. Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157156 Share on other sites More sharing options...
jsk1gcc Posted January 9, 2011 Author Share Posted January 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/223895-vat-function-into-session/#findComment-1157170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.