Código PHP:
<?php
session_start();
session_register('itemsEnCesta');
?><head>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<?php
$item=$_POST['item'];
$talle=$_POST['talle'];
$color=$_POST['color'];
$cantidad=$_POST['cantidad'];
$itemsEnCestaCant=$_SESSION['itemsEnCestaCant'];
$itemsEnCestaTalle=$_SESSION['itemsEnCestaTalle'];
$itemsEnCestaColor=$_SESSION['itemsEnCestaColor'];
$var=$_POST["agregar"];
$cod=$_GET["cod"];
if ($var == "Agregar")
{
if ($item && $talle && $color){
if (!isset($itemsEnCestaCant) && !isset($itemsEnCestaTalle) && !isset($itemsEnCestaColor)){
$itemsEnCestaCant[$item]=$cantidad;
$itemsEnCestaTalle[$item]=$talle;
$itemsEnCestaColor[$item]=$color;
}else{
foreach($itemsEnCestaCant as $k => $v){
if ($item==$k){
$itemsEnCestaCant[$k]+=$cantidad;
$encontrado=1;
}
}
if (!$encontrado) $itemsEnCestaCant[$item]=$cantidad;
}
}
$_SESSION['itemsEnCestaCant']=$itemsEnCestaCant;
$_SESSION['itemsEnCestaTalle']=$itemsEnCestaTalle;
$_SESSION['itemsEnCestaColor']=$itemsEnCestaColor;
}
if ($cod != "")
{
unset ($_SESSION['itemsEnCestaCant'][$cod]);
unset ($_SESSION['itemsEnCestaTalle'][$cod]);
unset ($_SESSION['itemsEnCestaColor'][$cod]);
$_SESSION['itemsEnCestaCant']=$itemsEnCestaCant;
$_SESSION['itemsEnCestaTalle']=$itemsEnCestaTalle;
$_SESSION['itemsEnCestaColor']=$itemsEnCestaColor;
}
?>
<html>
<style type="text/css">
<!--
.lista {
margin: 0px auto 20px auto;
border-collapse: collapse;
}
.formulario{
margin: 0px auto 20px auto;
}
-->
</style>
<body>
<!-- <form src="?=$PHP_SELF.?>" method="post"> -->
<!-------------------------------------------------------------------------------------------->
<div id="contenedor">
<form src="borrar.php" method="post">
<table width="393" class="formulario">
<!--DWLayoutTable-->
<br />
<thead>
<tr>
<th colspan="2"> Agregando producto</th>
<td width="34"></td>
</tr>
</thead>
<tbody>
<tr>
<td width="124">Código</td>
<td width="211"><input name="item" type="text" id="item" size="10" class="required number" /></td>
<td></td>
</tr>
<tr>
<td height="34" valign="top">Talle</td>
<td valign="top"><input name="talle" type="text" id="talle" size="20" class="required" /></td>
<td></td>
</tr>
<tr>
<td height="34" valign="top">Descripción</td>
<td valign="top"><input type="text" class="required" size="30" maxlength="200" /></td>
<td></td>
</tr>
<tr>
<td height="30" valign="top"><p>Color<br />
</p></td>
<td rowspan="3" valign="top"><p>
<input name="color" type="text" id="color" size="30" class="required" />
<br />
<br />
<input name="cantidad" type="text" id="cantidad" size="10" class="required number" />
</p></td>
<td></td>
</tr>
<tr>
<td height="11"></td>
<td></td>
</tr>
<tr>
<td height="31" valign="top">Cantidad</td>
<td></td>
</tr>
<tr>
<td height="1"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="36" colspan="3" valign="top"><div align="right">
<input name="agregar" type="submit" id="agregar" value="Agregar" />
<label></label>
</div></td>
</tr>
<tr>
<td height="1"></td>
<td></td>
<td></td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</form>
</div>
<!--------------------------------------------------------------------------------------------->
<form src="borrar.php" method="post">
Cód Articulo
<input type="text" name="item" size="20"><br>
Cuantas unidades <input type="text" name="cantidad" size="20"><br>
<input type="submit" name="agregar" value="Agregar">
<br>
</form>
<table width="683" border="1" cellpadding="1" cellspacing="1" class="lista"><!--DWLayoutTable-->
<thead>
<tr>
<th width="179">Codigo Art</th>
<th width="124">Imagén</th>
<th width="85">Talle</th>
<th width="93">Color</th>
<th width="148">Cantidad</th>
<th width="21"></th>
</tr>
</thead>
<tbody>
<?php
if (!isset($itemsEnCestaCant) && !isset($itemsEnCestaTalle) && !isset($itemsEnCestaColor)){
foreach($itemsEnCestaCant as $k => $v){
// $cant= $cant+$v;
echo '<form src="borrar.php" method="post">';
echo '<tr><td><div align="center">'.$k.'</div></td><td><div align="center">IMAGEN</div></td> <td><div align="center">'.$talle.'</div></td><td><div align="center">'.$color.'</div></td><td><div align="center">'.$v.'</div></td><td><a href="borrar.php?cod='.$k.'"><img src="delete.png"/></a><br></td></tr>';
echo '</form>';
}
}
?>
</table>
</body>
</html>