Still troubled with SESSION and VAT function

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

Still troubled with SESSION and VAT function

Post by jsk1gcc »

Hi, I could really do with some help putting the prices from two drop down boxes into sessions


To start with the user can choose two seats one from each drop down box

Code: Select all

//DROP DOWN BOX ONE
$extract =mysql_query("SELECT * FROM ride WHERE rideID ='1'");
$numrows = mysql_num_rows($extract);
//start of form
echo '<form method="post" name="f1" action="card.php">';
echo 'Please choose a seat:  '; 
echo"<select name='seat' >";
		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'];
		}  
echo '</select><br>'; 

//DROP DOWN BOX TWO
$extract2 =mysql_query("SELECT * FROM ride WHERE rideID ='1'");
$numrows = mysql_num_rows($extract2);
//start of form
echo '<form method="post" name="f2" action="card.php">';
echo 'Please choose a seat:  '; 
echo"<select  name='seat2' >";
		while( $row = mysql_fetch_assoc($extract2)) 
		{   
			$rideID = $row ['rideID'];
			$rideName = $row ['rideName'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat2'> $seatNumber </option>";
			$_SESSION['extract2']=$_POST['seat2'];
		}  
echo '</select><br>'; 
at the moment I have this :

Code: Select all


$query =mysql_query("SELECT price FROM ride WHERE rideID ='1' LIMIT 1");
while ($row=mysql_fetch_array($query))
{
echo $row['price'];
echo "<br>";

                $seatPrice1=($row['price']);
	        $seatPrice2=($row['price']*2);
		
		
		$vat1=17.5;
		
		function vat($vat, $row['price'])
			{
				return sprintf("%01.2f", ($vat*$row['price]/ 100));
			}
				$vatprice = vat(17.5, 2.50);
				
                $total1=($vatprice);
		$total2=($vatprice*2);	
		
		$endPrice1= ($total1+$seatPrice1);
		$endPrice2= ($total2+$seatPrice2);

What I need is $endPrice1 and $endPrice2 in $_SESSIONS so i an INSERT them in to the database 3 pages away from this query/VAT fucntion.
A look at the syntax and structure of the query would be a great help too =)

Can anyone help? Thanks. :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Still troubled with SESSION and VAT function

Post by social_experiment »

You forgot to add a ' in the line below, that will probably give you a syntax error if you execute the script.

Code: Select all

<?php return sprintf("%01.2f", ($vat*$row['price']/ 100)); ?>
You should assign the session variables when you have the values from the select menus, after the submit button is clicked.

Code: Select all

<?php
 session_start();
 // on card.php
 if (isset($_POST['seat2'])) {
  $_SESSION['extract2'] = $_POST['seat2'];
 }
?>
The option tag doesn't have a 'name' attribute. To pass your value along use the 'value' attribute

Code: Select all

<option value="25">25</option>
<!-- value retrieved here will be 25 -->
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply