Page 1 of 1

New to PHP - Basic, simple shopping cart

Posted: Mon May 10, 2010 2:13 am
by diablokicks
I am fairly new to using php, i have zymic free web hosting and am trying to implement a shopping cart. With zymic they won't let you use "outside connections" so it eliminates shopping cart software. I have come up with some code that looks promising for my needs, however i am having some issues with trying to get the shipping costs set. Let me explain before i give my code. The product is handmade Christmas stockings, so most likely individuals will only be ordering a quantity of 1 for each stocking, but possibly two different stockings. The shopping cart code i have will change the shipping costs if they order qty 2 or more of one product (shipping for first one is 6 dollars, then drops to 2 dollars for each additional stocking), but the shipping will be 6 dollars per each different stocking if they order different stockings. I would like to have the shipping be six dollars for the first initial stocking and increase by 2 dollars for each additional stocking.

I understand shipping 1 is initial for one product and shipping 2 is the incrementing after that. I thought about changing the serial numbers to all the same things, because is still shows them as different products, but if a qty is incorrect, if a user tries to correct it it will drop it from the cart.
SO to summarize, i would like to have an initial charge for the first stocking x amount, and then any other stocking that gets added be y amount. Any help will be greatly appreciated

Shipping php:

Code: Select all

<?

session_start();
// Load Settings
require_once('Local_Settings.php');

// Load Functions
require_once('inc/functions/Cart_Templates.php');
require_once('inc/functions/Cart_Functions.php');

// Check For Required Actions
if (is_numeric($_POST['cmd']))
{
  $cmd_In = $_POST['cmd'];
} else
{
  // Error, No ID, Send Away
  $cmd_In = '';
}

// Batch Add Items
if ($cmd_In==5)
{
  AddBatch($_POST,$Session_Prefix);
}

// Update Cart Content
if ($cmd_In==4)
{
  UpdateCart($_POST,$Session_Prefix);
}

// 
if ($cmd_In==1)
{
  // Add Item To Cart
  // Parse Optional Inputs Into Title & Serial
  $title_In = cleanvalue($_POST['Title']);
  $serialnum_In = cleanvalue($_POST['SerialNum']);
  $ImageURL_In = cleanvalue($_POST['ImageURL']);
  
  if (is_numeric($_POST['Price']))
  {
    $price_In = $_POST['Price'];
  } else
  {
    // Error, No ID, Send Away
    $price_In = '';
  }
  
  if (is_numeric($_POST['Shipping1']))
  {
    $shipping1_In = $_POST['Shipping1'];
  } else
  {
    // Error, No ID, Send Away
    $shipping1_In = '';
  }
  
  if (is_numeric($_POST['Shipping2']))
  {
    $shipping2_In = $_POST['Shipping2'];
  } else
  {
    // Error, No ID, Send Away
    $shipping2_In = '';
  }
  
  AddItemToCart($title_In,$serialnum_In,$price_In,$shipping1_In,$shipping2_In,$Session_Prefix,1,$ImageURL_In);
}

// Do HTML Header
Open_Cart_HTML($Site_Script_Root_Directory,$CSS_Filename,$Site_Title.' - Shopping Cart',"
<META NAME='keywords' CONTENT='".$Site_Title." Shopping Cart'>
");

include('inc/skin/Overall_Header.php');
?>
<br>
<table width="100%" border="0" align="center"> 
  <tr> 
    <td valign="top">  <div align="center">
<? echo Cart_Menu(1); ?><br />
      <div class="CartPageInfoBox CartPageInfoBG" style="width:500">
      <a href=index.html>Continue Shopping</a> <br/><br/>
      <span class='Bold'>Please Verify Your Order is Correct Before Continuing With Checkout:</span></div>
      <br />
      <table border="0">
        <tr>
          <td><div align="center" class="CartContentsBox CartContentsBG"><? echo DisplayEditableCart($Session_Prefix,$Currency_Symbol,$Currency_Code);?></div></td>
        </tr>
      </table><br />
    </div></td> 
  </tr> 
</table>
<br><br>

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=5815761;
var sc_invisible=1;
var sc_security="0a1546bf";
</script>

<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="web stats"
href="http://www.statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/5815761/0/0a1546bf/1/"
alt="web stats" ></a></div></noscript>
<!-- End of StatCounter Code -->

<?
include('inc/skin/Overall_Footer.php');
// Do HTML footer
Close_Cart_HTML($Site_Domain,$Site_Script_Root_Directory);

?>
And cart function:

Code: Select all

<?

function AddBatch($_POST,$Session_Prefix)
{
  // Check  For Batch Count
  if (is_numeric($_POST['Batch_Count']))
  {
    $Batch_Count = $_POST['Batch_Count'];
  } else
  {
  	// Error, No ID, Send Away
    $Batch_Count = 0;
  }

  // Using a for loop, check through each field in form looking for check box
  for ($i = 0; $i < $Batch_Count; $i++)
  {
  	$Cur_CheckBox = "checkbox".$i;
  	// If box is checked, add item to cart
  	if ($_POST[$Cur_CheckBox]==1)
  	{

  	  // Parse Optional Inputs Into Title & Serial
  	  $title_In = cleanvalue($_POST['Title'.$i]);
  	  $serialnum_In = cleanvalue($_POST['SerialNum'.$i]);

  	  if (is_numeric($_POST['Price'.$i]))
  	  {
    	$price_In = $_POST['Price'.$i];
  	  } else
  	  {
    	// Error, No ID, Send Away
    	$price_In = '';
  	  }

  	  if (is_numeric($_POST['Shipping1'.$i]))
  	  {
    	$shipping1_In = $_POST['Shipping1'.$i];
  	  } else
  	  {
    	// Error, No ID, Send Away
    	$shipping1_In = '';
  	  }

  	  if (is_numeric($_POST['Shipping2'.$i]))
  	  {
    	$shipping2_In = $_POST['Shipping2'.$i];
  	  } else
  	  {
    	// Error, No ID, Send Away
    	$shipping2_In = '';
  	  }

	  if (is_numeric($_POST['Quantity'.$i]))
  	  {
    	$Quantity_In = $_POST['Quantity'.$i];
  	  } else
  	  {
    	// Error, No ID, Send Away
    	$Quantity_In = '1';
  	  }


	  // Add Item To Cart
	  AddItemToCart($title_In,$serialnum_In,$price_In,$shipping1_In,$shipping2_In,$Session_Prefix,$Quantity_In);

  	} // end if
  } // end for
  header("location:ShoppingCart.php");
} // end function

// Add Item To Cart ************************************************************************************************************
function AddItemToCart($Title,$SerialNum,$Price,$Shipping1,$Shipping2,$Session_Prefix,$Quantity='1')
{

  // Check To See If Cart Exists, And Set Count Accordingly
  if ($_SESSION[$Session_Prefix.'Item_Count']!="")
  {
    $Item_Row = $_SESSION[$Session_Prefix.'Item_Count'] + 1;
  } else
  {
    $Item_Row = 1;
  }

  // check to see if the new item's serial num is already in the shopping cart
  $searchflag = "";
  for ($i = 1; $i < $Item_Row; $i++)
  {
    $searchserialnum = "serialnum".$i;
	if ($_SESSION[$Session_Prefix.$searchserialnum]==$SerialNum)
    {
      $searchflag = $i;
    }
  }

  //If no match was found add the new info as a new entry (Item_Row)
  if ($searchflag=="")
  {
	// Prepare Cart Field Titles For New Entry
    $Title_serialnum = "serialnum".$Item_Row;
    $Title_shippinga = "shippinga".$Item_Row;
    $Title_shippingb = "shippingb".$Item_Row;
    $Title_title = "title".$Item_Row;
    $Title_price = "price".$Item_Row;
	$Title_quantity = "quantity".$Item_Row;

	$_SESSION[$Session_Prefix.$Title_serialnum] = $SerialNum;
	$_SESSION[$Session_Prefix.$Title_title] = $Title;
	$_SESSION[$Session_Prefix.$Title_shippinga] = $Shipping1;
	$_SESSION[$Session_Prefix.$Title_shippingb] = $Shipping2;
	$_SESSION[$Session_Prefix.$Title_price] = $Price;
	$_SESSION[$Session_Prefix.$Title_quantity] = $Quantity;
	$_SESSION[$Session_Prefix."Item_Count"] = $Item_Row;

  } else
  {
    //Otherwise just update the quanity of this item/serialnum

    $quantity = "quantity".$searchflag;
	$newquantity = $_SESSION[$Session_Prefix.$quantity] + $Quantity;
	$_SESSION[$Session_Prefix.$quantity] = $newquantity;
  } // end searchflag if
  header("location:ShoppingCart.php");
}


// ****************************************************************************************************************************************
function DisplayEditableCart($Session_Prefix,$Currency_Symbol,$Currency_Code)
{

  $RowCount=$RowCount+1;
  $TempCol=$RowCount%2+1;

  $Output = '';
  $Output = $Output.'<div align="center" class="Bold">
	  <table width="600" border="1" align="center" cellpadding="0" cellspacing="0">';

  if (isset($_SESSION[$Session_Prefix.'Item_Count']) && $_SESSION[$Session_Prefix.'Item_Count']!=0)
  {
    $CheckOrd=1;
    $Output = $Output.'<tr>
          <td width="16%" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Qty</div></td>
          <td width="10%" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Remove</div></td>
		  <td colspan="2" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Title / Serial#</div></td>
          <td width="15%" class="RepeatRowColor'.$TempCol.'"><div align="right" class="FieldTitleColor'.$TempCol.'">Price</div></td>
        </tr>
       <form id="form2" name="form2" method="post" action="ShoppingCart.php">';

    //Setup Cart Vars
    $displaysubtotal=0;
    $displayshippingtotal=0;
    $displaytotal=0;
    $displaynewshipping=0;
    $displaynewprice=0;

    $final = $_SESSION[$Session_Prefix.'Item_Count']+1;
    $cnt=1;

	for ($i = 1; $i < $final; $i++)
	{
	  $RowCount=$RowCount+1;
      $TempCol=$RowCount%2+1;

	  // Setup Vars for this Row
	  $displayserialnum = "serialnum".$i;
	  $displayshippinga = "shippinga".$i;
	  $displayshippingb = "shippingb".$i;
	  $displaytitle = "title".$i;
	  $displayprice = "price".$i;
	  $displayquantity = "quantity".$i;
	  $displayremove = "remove".$i;

	  // Calculate The Total Shipping For This Item
	  if ($_SESSION[$Session_Prefix.$displayquantity]>1)
	  {
  	  	$displaynewshipping = ($_SESSION[$Session_Prefix.$displayshippinga] + ($_SESSION[$Session_Prefix.$displayshippingb] * ($_SESSION[$Session_Prefix.$displayquantity] - 1)));
	  } else
	  {
	    $displaynewshipping = $_SESSION[$Session_Prefix.$displayshippinga];
	  }
          
	  // Calculate The price For This Item
	  $displaynewprice = $_SESSION[$Session_Prefix.$displayprice] * $_SESSION[$Session_Prefix.$displayquantity];

	  $Output = $Output.'<tr>
          <td class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'"><input name="'.$displayquantity.'" type="text" value="'.$_SESSION[$Session_Prefix.$displayquantity].'" size="3" maxlength="4"></div></td>
		  <td class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'"><input name="'.$displayremove.'" type="checkbox" value="1"></div></td>
          <td colspan="2" class="RepeatRowColor'.$TempCol.'"><div align="left" class="DataTextColor'.$TempCol.'">'.$_SESSION[$Session_Prefix.$displaytitle].'<br />
                  '.$_SESSION[$Session_Prefix.$displayserialnum].'</div></td>
          <td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaynewprice, 2, '.', '').'</div></td>
        </tr>';

	  // Update The Total Vars
	  $displaysubtotal = $displaysubtotal + $displaynewprice;
	  $displayshippingtotal = $displayshippingtotal + $displaynewshipping;
          if ($displayshippingtotal > 15)
              $displayshippingtotal = 15;
	} // end For

	$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

	// Calculate Totals
	$displaytotal = ($displayshippingtotal + $displaysubtotal);
	$Output = $Output.'<tr>
          <td colspan="4" class="RepeatRowColor'.$TempCol.'"><div align="right" class="FieldTitleColor'.$TempCol.'">*Total ('.$Currency_Code.'):</div></td>
          <td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaysubtotal, 2, '.', '').'</div></td>
        </tr>';

		$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

        $Output = $Output.'<tr>
          <td colspan="5" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">*Shipping
                costs will be calculated upon checkout.</div></td>
        </tr>';

		$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

$Output = $Output.'<tr><td colspan="5" class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'">

<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="50%"><div align="center">

  <input name="cmd" type="hidden" id="cmd" value="4">
<div align="center" class="">
        <input name="Submit" type="submit" value="Update Cart"/>
      </div>
</div></td>
<td><div align="center">
  <div align="center" class=""><a href="ChoosePayment.php" class="InSiteLink"><img src="img/checkout.gif"></a> </div>
  </div></td>
</tr>
</table>
</div></td>
</tr>
  </form></table>';
  } else
  {
	$Output = $Output.'<tr>
          <td colspan="5" class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'"><font color="red" size="8">...Cart is Empty... </font><br />
          </div></td>
        </tr>
		</table>';

  } // end if

  $Output = $Output.'
  </div>';

  return $Output;
}

//********************************************************************************************************************
function UpdateCart($_POST,$Session_Prefix)
{

  // Loop Through Form Data
  for ($updatecnt = 1; $updatecnt < ($_SESSION[$Session_Prefix.'Item_Count'] + 1); $updatecnt++)
  {
    // Create Field Names
	$updatequantity = "quantity".$updatecnt;
	$updateremove = "remove".$updatecnt;

	// Check Numeric Inputs
	if (is_numeric($_POST[$updatequantity]))
	{
	  // Quanity is numeric, update cart
	  $_SESSION[$Session_Prefix.$updatequantity] = $_POST[$updatequantity];
	}

	if (is_numeric($_POST[$updateremove]))
	{
	  // Remove is numeric, update cart
	  if ($_POST[$updateremove]=="1")
	  {
	    $_SESSION[$Session_Prefix.$updatequantity] = 0;
	  }
	}

	//Make Empty OR non-numeric quantities into zeros
	if ($_SESSION[$Session_Prefix.$updatequantity]=="" || !is_numeric($_SESSION[$Session_Prefix.$updatequantity]))
    {
      $_SESSION[$Session_Prefix.$updatequantity] = "0";
    }

	// Delete Serial Num for 0 quantity / removed items
	if ($_SESSION[$Session_Prefix.$updatequantity]=="0")
    {
      $updateserialnum = "serialnum".$updatecnt;
	  $_SESSION[$Session_Prefix.$updateserialnum] = "";
    }

  }

  // Repair The Cart
  // Run the Repair Process Until No Gaps Are Found!
  $gaps = "1";
  while ($gaps != 0)
  {
   $gaps = "0";

   // Main Loop For Dealing With Removing Deleted Items
   for ($updatecnt = 1; $updatecnt < ($_SESSION[$Session_Prefix.'Item_Count'] + 1); $updatecnt++)
   {
     $updateserialnum = "serialnum".$updatecnt;
	 // Check to see if the serial num exists
	 if ($_SESSION[$Session_Prefix.$updateserialnum]=="")
	{
	  // No Serialnum - gap found
	  $gaps = "1";

	  // Set Field Titles For This And THis+1 Row:
	  $nextrow=$updatecnt+1;
	  $previousrow=$updatecnt-1;

	  $updateserialnum = "serialnum".$updatecnt;
	  $updateserialnumnext = "serialnum".$nextrow;
	  $updateshippinga = "shippinga".$updatecnt;
	  $updateshippinganext = "shippinga".$nextrow;
	  $updateshippingb = "shippingb".$updatecnt;
	  $updateshippingbnext = "shippingb".$nextrow;
	  $updatetitle = "title".$updatecnt;
	  $updatetitlenext = "title".$nextrow;
	  $updateprice = "price".$updatecnt;
	  $updatepricenext = "price".$nextrow;
	  $updatequantity = "quantity".$updatecnt;
	  $updatequantitynext = "quantity".$nextrow;

	  // Check To See If EOF
	  if ($nextrow < ($_SESSION[$Session_Prefix.'Item_Count'] + 1))
	  {
  		// Not EOF
		// Copy NextRow Info Down To This Row (and delete NextRow's SerialNum)
		$_SESSION[$Session_Prefix.$updateserialnum] = $_SESSION[$Session_Prefix.$updateserialnumnext];
		$_SESSION[$Session_Prefix.$updateshippinga] = $_SESSION[$Session_Prefix.$updateshippinganext];
		$_SESSION[$Session_Prefix.$updateshippingb] = $_SESSION[$Session_Prefix.$updateshippingbnext];
		$_SESSION[$Session_Prefix.$updatetitle] = $_SESSION[$Session_Prefix.$updatetitlenext];
		$_SESSION[$Session_Prefix.$updateprice] = $_SESSION[$Session_Prefix.$updatepricenext];
		$_SESSION[$Session_Prefix.$updatequantity] = $_SESSION[$Session_Prefix.$updatequantitynext];
		$_SESSION[$Session_Prefix.$updateserialnumnext] = "";
	  } else
	  {
	    // EOF
		//
		$_SESSION[$Session_Prefix.$updateserialnum] = "";
		$_SESSION[$Session_Prefix.$updateshippinga] = "";
		$_SESSION[$Session_Prefix.$updateshippingb] = "";
		$_SESSION[$Session_Prefix.$updatetitle] = "";
		$_SESSION[$Session_Prefix.$updateprice] = "";
		$_SESSION[$Session_Prefix.$updatequantity] = "";
		$_SESSION[$Session_Prefix."Item_Count"] = $previousrow;

	  }  // end EOF check if

	}
   } // end main loop for dealing with removing items
  } //endwhile
  header("location:ShoppingCart.php?u");
}

// ****************************************************************************************************************************************
function DisplayCartWShipping($Session_Prefix,$Currency_Symbol,$Currency_Code)
{
  $RowCount=$RowCount+1;
  $TempCol=$RowCount%2+1;
  $Output = '';

  $Output = $Output.'<table width="600" border="1" align="center" cellpadding="0" cellspacing="0">';

  if (isset($_SESSION[$Session_Prefix.'Item_Count']) && $_SESSION[$Session_Prefix.'Item_Count']!=0)
  {
	$CheckOrd=1;
	$Output = $Output.'<tr>
	<td width="11%" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Qty</div></td>
	<td width="52%" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Title / <br />Serial#</div></td>
	<td width="21%" class="RepeatRowColor'.$TempCol.'"><div align="center" class="FieldTitleColor'.$TempCol.'">Shipping</div></td>
	<td width="16%" class="RepeatRowColor'.$TempCol.'"><div align="right" class="FieldTitleColor'.$TempCol.'">Price</div></td>
	</tr>';


	//Setup Cart Vars
	$displaysubtotal=0;
	$displayshippingtotal=0;
	$displaytotal=0;
	$displaynewshipping=0;
	$displaynewprice=0;

	$final = $_SESSION[$Session_Prefix.'Item_Count']+1;
	$cnt=1;

	for ($i = 1; $i < $final; $i++)
	{
	$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

	  // Setup Vars for this Row
	  $displayserialnum = "serialnum".$i;
	  $displayshippinga = "shippinga".$i;
	  $displayshippingb = "shippingb".$i;
	  $displaytitle = "title".$i;
	  $displayprice = "price".$i;
	  $displayquantity = "quantity".$i;
	  $displayremove = "remove".$i;


	  // Calculate The Total Shipping For This Item
	  if ($_SESSION[$Session_Prefix.$displayquantity]>1)
	  {
  		$displaynewshipping = ($_SESSION[$Session_Prefix.$displayshippinga] + ($_SESSION[$Session_Prefix.$displayshippingb] * ($_SESSION[$Session_Prefix.$displayquantity] - 1)));
	  } else
	  {
  		$displaynewshipping = $_SESSION[$Session_Prefix.$displayshippinga];
	  }


	  // Calculate The price For This Item
	  $displaynewprice = $_SESSION[$Session_Prefix.$displayprice] * $_SESSION[$Session_Prefix.$displayquantity];

	  $Output = $Output.'<tr>
	  <td class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'">'.$_SESSION[$Session_Prefix.$displayquantity].'</div></td>
	  <td class="RepeatRowColor'.$TempCol.'"><div align="left" class="DataTextColor'.$TempCol.'">'.$_SESSION[$Session_Prefix.$displaytitle].'<br>'.$_SESSION[$Session_Prefix.$displayserialnum].'</div></td>
	  <td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaynewshipping, 2, '.', '').'</div></td>
	  <td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaynewprice, 2, '.', '').'</div></td>
	  </tr>';

	  // Update The Total Vars
	  $displaysubtotal = $displaysubtotal + $displaynewprice;
	  $displayshippingtotal = $displayshippingtotal + $displaynewshipping;
          if ($displayshippingtotal > 15)
              $displayshippingtotal = 15;
	} // end For

	$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

  	// Calculate Totals
  	$displaytotal = ($displayshippingtotal + $displaysubtotal);

  	$Output = $Output.'<tr>
	<td colspan="2" class="RepeatRowColor'.$TempCol.'"><div align="right" class="FieldTitleColor'.$TempCol.'">Sub Totals ('.$Currency_Code.'):</div></td>
	<td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displayshippingtotal, 2, '.', '').'</div></td>
	<td class="RepeatRowColor'.$TempCol.'"><div align="right" class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaysubtotal, 2, '.', '').'</div></td>
	</tr>';

	$RowCount=$RowCount+1;
    $TempCol=$RowCount%2+1;

	$Output = $Output.'<tr>
	<td colspan="4" class="RepeatRowColor'.$TempCol.'"><div align="right" class="FieldTitleColor'.$TempCol.'">Total With Shipping ('.$Currency_Code.'): <span class="DataTextColor'.$TempCol.'">'.$Currency_Symbol.' '.number_format($displaytotal, 2, '.', '').'</span></div></td>
	</tr>';

  } else
  {
  	$Output = $Output.'<tr>
                  <td colspan="4" class="RepeatRowColor'.$TempCol.'"><div align="center" class="DataTextColor'.$TempCol.'"><font color="red" size="8">...Cart is Empty...</font> <br>
                    </div></td>
            </tr>';

  } // end if

  $Output = $Output.'</table>';
  return $Output;
}
// 8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
function GetCartTotals($Session_Prefix)
{
  $Output = '';

  if (isset($_SESSION[$Session_Prefix.'Item_Count']) && $_SESSION[$Session_Prefix.'Item_Count']!=0)
  {
	$CheckOrd=1;

	//Setup Cart Vars
	$displaysubtotal=0;
	$displayshippingtotal=0;
	$displaytotal=0;
	$displaynewshipping=0;
	$displaynewprice=0;

	$final = $_SESSION[$Session_Prefix.'Item_Count']+1;

	for ($i = 1; $i < $final; $i++)
	{

	  // Setup Vars for this Row
	  $displayserialnum = "serialnum".$i;
	  $displayshippinga = "shippinga".$i;
	  $displayshippingb = "shippingb".$i;
	  $displaytitle = "title".$i;
	  $displayprice = "price".$i;
	  $displayquantity = "quantity".$i;
	  $displayremove = "remove".$i;

	  // Calculate The Total Shipping For This Item
	  if ($_SESSION[$Session_Prefix.$displayquantity]>1)
	  {
  		$displaynewshipping = ($_SESSION[$Session_Prefix.$displayshippinga] + ($_SESSION[$Session_Prefix.$displayshippingb] * ($_SESSION[$Session_Prefix.$displayquantity] - 1)));
	  } else
	  {
  		$displaynewshipping = $_SESSION[$Session_Prefix.$displayshippinga];
	  }

	  // Calculate The price For This Item
	  $displaynewprice = $_SESSION[$Session_Prefix.$displayprice] * $_SESSION[$Session_Prefix.$displayquantity];

	  // Update The Total Vars
	  $displaysubtotal = $displaysubtotal + $displaynewprice;
	  $displayshippingtotal = $displayshippingtotal + $displaynewshipping;
          if ($displayshippingtotal > 15)
              $displayshippingtotal = 15;
	} // end For

  	// Calculate Totals
  	$displaytotal = ($displayshippingtotal + $displaysubtotal);

  	$Output['Shipping_Total']=$displayshippingtotal;
	$Output['Sub_Total']=$displaysubtotal;
	$Output['Order_Total']=$displaytotal;

  }

  return $Output;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function cleanvalue($strvalue) { // remove dangerous data from the value passed
	$newvalue = strip_tags($strvalue);
	$newvalue = str_replace("|", " ", $newvalue);
	$newvalue = str_replace("'", " ", $newvalue);
	$newvalue = stripslashes($newvalue);
	return $newvalue;
}
?>