i am using
<?php
session_start();
require_once 'update.php';
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<title>DwsComputers.com -- Creativity Through Technology</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Idea by: Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL: [url]http://fineline.xs.mw[/url] -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! [url]http://javascript.internet.com[/url] -->
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=600,left = 200,top = 200');");
}
// End -->
</script>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function popitup(url)
{
newwindow=window.open(url,'name','height=200,width=200');
if (window.focus) {newwindow.focus()}
return false;
}
// -->
</SCRIPT>
<style type="text/css">
<!--
.style2 {color: #FF0000}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="500" border="0" align="center" cellpadding="1" cellspacing="1" class="tablebord1">
<tr>
<td><table width="500" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><?php include'header.php'?></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td align="left" valign="top"><table width="100%" border="0">
<tr>
<td width="18%" valign="top"> </td>
<td width="82%" valign="top"><p>
<?php
include 'config.php';
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());
$query=mysql_query("INSERT INTO `orders` (payment_status,order_main,order_status,sessionid,userid,order_date) VALUES ('NOT PAID','OPEN','PENDING PAYMENT','".session_id()."','".$_SESSION['username']."','".time()."')");
$orderid=mysql_insert_id();
echo "Cart Contents:";
if (is_array($_SESSION['products']))
{
$i=1;
foreach($_SESSION['products'] as $key=>$val)
{
if ($i==2)
{
$query2=mysql_query("SELECT * FROM `products` WHERE id='".$val."'");
if (mysql_num_rows($query2)==1)
{
$prodinfo=mysql_fetch_assoc($query2);
$checkitem=mysql_query("SELECT * FROM `shopping_cart_order_items` WHERE sessionid='".session_id()."' AND productid='".$val."'");
if (mysql_num_rows($checkitem)==1)
{
$updatequery=mysql_query("UPDATE shopping_cart_order_items SET quantity=quantity+1 WHERE sessionid='".session_id()."' AND productid='".$val."'");
echo "<br>".$val." --- ".$prodinfo['productname']." --- Price: £".$prodinfo['price']." --- <a href=\"infobox.php?id=$val\" onClick=\"return popitup('infobox.php?id=$val')\"><img src=\"i_help.gif\" width=\"16\" height=\"16\" border=\"0\"></a>";
}
else
{
$count=$count++;
$query3=("INSERT INTO shopping_cart_order_items (productname,orderid,sessionid,productid,price,quantity) VALUES ('".$prodinfo['productname']."','".$orderid."','".session_id()."','".$val."','".$prodinfo['price']."','1')");
mysql_query($query3) or die (mysql_error());
echo "<br>".$val." --- ".$prodinfo['productname']." --- Price: £".$prodinfo['price']." --- <a href=\"infobox.php?id=$val\" onClick=\"return popitup('infobox.php?id=$val')\"><img src=\"i_help.gif\" width=\"16\" height=\"16\" border=\"0\"></a>";
}
@$carttotal=@$carttotal+$prodinfo['price'];
$updatecart=mysql_query("UPDATE `orders` SET numitems=numitems+1 WHERE id='".$orderid."'");
}
$i=1;
} $c = array($carttotal+20.00);
$totalvalue = "".array_sum($c)."";
$i++;
}
$updatecart=mysql_query("UPDATE `orders` SET total='$carttotal' WHERE id='$orderid'");
}
@$totalprice=$r['price']+$totalprice;
$c = array($carttotal+20.00);
$totalvalue = "".array_sum($c)."";
echo "<br><br>Total Price: In GBP £$totalvalue<br>";
$d = array(($carttotal+20.00)*1.84987);
echo "Cost Dollars (for Payment) = $".array_sum($d)."\n<br>";
echo "<BODY onLoad=\"javascript:popUp('https://www.2checkout.com/cgi-bin/sbuyers/cartpurchase.2c?sid=*******&total=".array_sum($d)."&cart_order_id=$orderid')\">";
//////LINE HERE////////
$stock_update="UPDATE products SET stock=stock-1 WHERE id='".$val."'";
mysql_query($stock_update) or die (mysql_error());
//////LINE ABOVE//////
// Begin Session Unregistering
$products= $_GET['products'];
$product = $_GET['proid'];
unset($_SESSION['products'][$key]);
// End Session Unregistering
?>
<strong><br>
</strong></p>
<p align="center"><strong> Stage 2 Will pop up in a new window <span class="style2"><br>
Stage 1</span> Stage 2 Stage 3 <br>
<br>
</strong></p></td>
</tr>
</table>
<br>
<br><?php include 'footer.php'?></td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
See the bit with ////LINE HERE//// in it.
I am trying to take one away from the total of stock in the products DB.
This works fine when there is only one item in the cart.
If there is more than one in the cart it does not work proberly, can anyone see why?
DAvid