$n=" ";
//echo $client;
/* nullify arrays */
$row=array();$cartitem=array();
/* nullify strings */
$content="";$itemnum="";$itemold="";$itemnew="";$query="";$retval="";
/* set int/long's to 0 */
$subtotal=0;$total=0;$cost=0;$stcost=0;$shipping=0;
$stype="check";
for ($z=1;$z<=2;$z++)
{
for ($x=0;$x<=$countt;$x++)
{
$temp=$stype.$x;
if ($$temp!="")
{
$retval=explode("&",$$temp);
$item=$retval[0];
$itemtype=$retval[1];
}
if ($item)
{
//fetch the values from the table.
$query_result_handle = mysql_query ("SELECT catalog_id,title,price,mp3price FROM songs WHERE catalog_id='$item'",$db);
$row = mysql_fetch_array ($query_result_handle);
if(!$row[1]) { $content="Invalid item number."; }
else
{ if ($itemtype=="MID")
$cost=sprintf ("%01.2f", $row[2]);
else
$cost=sprintf ("%01.2f", $row[3]);
$addqty=1;
$additem=$item;
$itemtype=$itemtype;
//echo "F items here ".$additem;
?>
}
$query="SELECT * FROM carts WHERE client='$client'";
$query_result_handle = mysql_query ($query);
$row = mysql_fetch_row ($query_result_handle);
$inv=1;
$addqty=$inv;
if($row[0])
{ //append all items into the array.
$cartitem = $row[2]."&cartitem[]=".$additem."-".$itemtype;
$itemwithtype=$additem."-".$itemtype;
if (strstr($row[2],$itemwithtype)==true)
{
}
else
{//update the cart with the new value.
$query="UPDATE carts SET items=\"$cartitem\" WHERE client='$client'";
// echo $query."
";
$query_result_handle = mysql_query ($query);
}
}
else
{
//if it is the first transaction,insert the data
//echo "additem is".$additem;
$itemstr="cartitem[]=".$additem."-".$itemtype;
$thisdate= date("Y-m-d");
$query="INSERT INTO carts (client,items,insdate) VALUES (\"$client\",\"$itemstr\",\"$thisdate\")";
//echo $query;
$query_result_handle = mysql_query ($query);
}
}
}
$stype="check1";
}
$view="cart";
/*
* Requests from navigation column
*/
if($type)
{
$query="SELECT catalog_id,title,price,artist,mp3price FROM songs WHERE catalog_id='$type'";
$query_result_handle = mysql_query ($query);
for ($count = 1; $row = mysql_fetch_row ($query_result_handle);
++$count)
{
$thumb="";
parse_str($row[3]);
if ($itemtype=="MID")
$cost=sprintf ("%01.2f", $row[2]);
else
$cost=sprintf ("%01.2f", $row[4]);
}
}
/*
* Inclusion script which handles:
* > View cart contents
* > Update quantities
* > Checkout
*/
include("cartjob.php");
?>