Jump to content

function trouble


mindapolis

Recommended Posts

I wrote a simple sales tax function but it keeps come back with a sales tax of 0 the price is coming from a database. 

 


function TotalSalesTax($price)
{
	$salesTax = .07;
	$TotalSalesTax = $price * $salesTax;
    number_format($TotalSalesTax, 2);	
	return $TotalSalesTax;		
}

 

<tr>  
    <td></td>  
    <td>Sales Tax:  </td>
    <td><?php echo TotalSalesTax($price);?>  	</td> 
</tr>

 

product page that the price comes from

<?php
session_start();
if(!isset($_SESSION['quantity']))

{
  $_SESSION['quanity']=array(); //if there are no quantities selected, the array is empty
  if(is_array($_POST['quantity']))//if there are items in the cart
{
  echo $quantity;
  header("location: checkOut.php");
}
}
require_once("functions.php");
?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
td {
border-top-style: solid; 
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #30C;
border-right-color: #30C;
border-bottom-color: #30C;
border-left-color: #30C;
}
#productCatalog {
width:400px;   
margin-right: auto;
margin-left: auto;
}
</style>
<link href="doggyTreats.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
logo();
navBar();
echo "<div id=\"productCatalog\">";
echo "<form action=\"checkOut.php\" method=\"post\" name=\"catalog\">";
  
DatabaseConnection();  

  $query = "SELECT * FROM treats"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0;

        echo "<table>";
        while ($row = mysql_fetch_array($result_set))
        {
	echo"<tr><td width=\"2s00px\"><img src=\"{$row['product_pic']}\" /></td><td width=\"200px\">{$row['product_title']}.<br /><br />{$row['product_Description']}.<br /> Price:  \${$row['price']}.<br /><br />Quantity <input name=\"quantity\" type=\"text\" size=\"2\" /></td></tr>";
        }
		echo "<tr>"; 
		echo "<td><input name=\"submit\" type=\"submit\" value=\"Proceed to Checkout\" />"; 
	echo "</table>";    
	echo "</form>";
echo "</div>";
footer();
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/251869-function-trouble/
Share on other sites

I'll be honest, I haven't read the entire script. But you do have a typo near the start which is probably the issue:

$_SESSION['quanity']=array(); //if there are no quantities selected, the array is empty

should be

$_SESSION['quantity']=array(); //if there are no quantities selected, the array is empty

missing the first 't' in 'quantity'

Link to comment
https://forums.phpfreaks.com/topic/251869-function-trouble/#findComment-1291483
Share on other sites

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.