Thanks Bastien.
It s true items overwriting each other. I send a Shopping Cart code. The code is strange, but i hope you will find a solution.
Thanks a lot!
<?
// Shopping cart -- Argus & Freeland -- uses PHP4 sessions
// Set these to suit
$self = $PHP_SELF; // this script
$shop = "shop.htm"; // return page
$ckout = "cart0.php?.SID";
/* Things your script can set on query string:
item=xxx Add item
qty=n Quantity to add (default 1)
del=n Delete n
*/
session_register("cart");
include("itemdb.inc");
function getitem($it) { // look up item, price, etc.
$db = new DB_Item;
$db->query("select sifra,KNJIGA_ID,naslov,(cijena-popust)spopustom from knjiga where KNJIGA_ID='$it'");
if (!$db->next_record()) {
return array("0.00","***");
}
return array($db->f("spopustom"),$db->f("naslov"));
}
// inform checkout that we were here
$cart[0]="ready";
if ($contpage!="") $shop=$contpage;
function delit($del) {
global $cart;
for ($i=$del;$i<count($cart)-1;$i++) {
$cart[$i]=$cart[$i+1];
}
unset($cart[$i]);
}
// getting ready to leave so update totals
if ($More!="" || $Update!="" || $Out!="") {
for ($i=count($cart)-1;$i>0;$i--)
{
if ($q[$i]==0) {
delit($i);
} else {
list($v,$oq)=$cart[$i];
$cart[$i]=array($v,$q[$i]);
}
}
}
if ($Out!="") { // checkout
header("Location: $ckout?" . SID);
exit;
}
if ($More!="") { // continue shopping
header("Location: $shop");
exit;
}
if ($del!="") { // delete item
delit($del);
// get rid of query string
header("Location: $self?" . SID);
exit;
}
if ($KNJIGA_ID!="") { // insert item
list ($d1,$d2) = getitem($KNJIGA_ID);
$n=1;
if ($qty!="") $n=$qty;
if ($d2!="***")
$cart[]=array($KNJIGA_ID,$n);
// get rid of query string
header("Location: $self?" . SID);
exit;
}
?>
<HTML>
<HEAD><TITLE>Your shopping cart</TITLE>
</HEAD>
<body background="glotextb.gif">
<CENTER>
<IMG SRC=banner.gif HEIGHT=60 WIDTH=600>
</CENTER>
<h1>Your Shopping Cart</H1>
<FORM ACTION=<? print $self; ?> METHOD=POST>
<TABLE BORDER=1 WIDTH=75%>
<? if (count($cart)>1) { ?>
<TR BGCOLOR=GRAY><B>
<TD><B>Item</B></TD><TD><B>Quantity</B></TD>
<TD><B>Description</B></TD><TD><B>Unit Price</B></TD>
<TD><B>Total</B></TD><TD> </TD></TR>
<? } ?>
<?
$ptotal=0;
for ($i=1 ; $i<sizeof($cart);$i++) {
list($it,$q) = $cart[$i];
if ($it=="deleted") continue;
list($p,$d) = getitem($it);
print "<TR><TD>" . $it . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fit[$i]' VALUE='$it'>";
print "<TD><INPUT SIZE=5 NAME=\"q[$i]\" VALUE=" . $q . "></TD>";
print "<TD>" . $d . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fd[$i]' VALUE='$d'>";
print "<TD ALIGN=RIGHT >" . sprintf("%01.2f",$p) . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fp[$i]' VALUE='$p'>";
$lv =sprintf("%01.2f", $p $q);
$ptotal = $ptotal + ($p $q);
print "<TD ALIGN=RIGHT>" . $lv . "</TD>";
print "<TD ALIGN=CENTER>" . "<a href=$self?del=" . $i . ">Delete</A></TR>";
}
?>
</TABLE>
<?
if (count($cart)<=1) print "<P>Your cart is empty</P>";
?>
<BR>
<? if (count($cart)>1) {
$fmt=sprintf("<BR>Total = %01.2f<BR>",$ptotal);
print $fmt;
}
?>
<BR>
<TABLE>
<TR><TD><INPUT TYPE=Submit Value="Continue Shopping" Name=More></TD>
<? if (count($cart)>1) { ?>
<TD><INPUT TYPE=Submit Value="Update Totals" Name=Update></TD>
<TD><Input Type=Submit Value="Check Out" Name=Out></TD>
<? } ?>
</TR></TABLE>
</FORM>
</BODY>
</HTML>