Hice la pagina siguiento algun tutorial que encontre, utilizando una libreria, mejor, os pongo aqui los archivos que hice:
En primer lugar, una serie de páginas, con los productos, tal como:
Código PHP:
Ver original
<a href="mete_producto.php?id=162586&codigo=162586&nombre=Mascara_de_pestanas_SuperExtend_Black&precio=6.95"><img src="images/carrito.jpg" width="30" height="30"></a>
lib_carrito.php
Código PHP:
Ver original
<? ?> <html> <head> <title>Avon online</title> </head> <body> <? $_SESSION["ocarrito"] = new carrito(); } class carrito { var $num_productos; var $array_id_prod; var $array_codigo_prod; var $array_nombre_prod; var $array_precio_prod; function carrito () { $this->num_productos=0; } function introduce_producto($id_prod,$codigo_prod,$nombre_prod,$precio_prod){ $this->array_id_prod[$this->num_productos]=$id_prod; $this->array_codigo_prod[$this->num_productos]=$codigo_prod; $this->array_nombre_prod[$this->num_productos]=$nombre_prod; $this->array_precio_prod[$this->num_productos]=$precio_prod; $this->num_productos++; } function elimina_producto($linea){ $this->array_id_prod[$linea]=0; } function imprime_carrito(){ $suma = 0; echo '<table border=1 cellpadding="3"> <tr> <td><b>Codigo</b></td> <td><b>Nombre producto</b></td> <td><b>Precio</b></td> <td> </td> </tr>'; for ($i=0;$i<$this->num_productos;$i++){ if($this->array_id_prod[$i]!=0){ echo '<tr>'; echo "<td>" . $this->array_codigo_prod[$i] . "</td>"; echo "<td>" . $this->array_nombre_prod[$i] . "</td>"; echo "<td>" . $this->array_precio_prod[$i] . "</td>"; echo "<td><a href='eliminar_producto.php?linea=$i'>Eliminar producto</td>"; echo '</tr>'; $suma += $this->array_precio_prod[$i]; } } //muestro el total echo "<tr><td><b>TOTAL:</b></td><td> <b>$suma</b></td><td> </td></tr>"; } } ?> </body>
El archivo mete_producto.php
Código PHP:
Ver original
<? include("lib_carrito.php"); $_SESSION["ocarrito"]->introduce_producto($_GET["id"], $_GET["codigo"], $_GET["nombre"], $_GET["precio"]); ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Avon online</title> <style type="text/css"> <!-- #banner_graphic { position:absolute; left:20px; top:20px; width:700px; height:92px; z-index:1; } #body_main_heder { position:absolute; left:20px; top:112px; width:700px; height:25px; z-index:2; } #Layer1 { position:absolute; left:20px; top:137px; width:150px; height:25px; z-index:3; } #Layer2 { position:absolute; left:20px; top:187px; width:150px; height:25px; z-index:4; } #Layer3 { position:absolute; left:20px; top:237px; width:150px; height:25px; z-index:5; } #Layer4 { position:absolute; left:20px; top:287px; width:150px; height:25px; z-index:6; } #Layer5 { position:absolute; left:20px; top:337px; width:150px; height:25px; z-index:7; } #Layer6 { position:absolute; left:20px; top:387px; width:150px; height:25px; z-index:8; } #Layer7 { position:absolute; left:20px; top:437px; width:150px; height:25px; z-index:9; } #Layer38 { position:absolute; left:20px; top:162px; width:150px; height:25px; z-index:37; background-color: #E06D68; } #Layer39 { position:absolute; left:20px; top:212px; width:150px; height:25px; z-index:38; background-color: #E06D68; } #Layer40 { position:absolute; left:20px; top:262px; width:150px; height:25px; z-index:39; background-color: #E06D68; } #Layer41 { position:absolute; left:20px; top:312px; width:150px; height:25px; z-index:40; background-color: #E06D68; } #Layer42 { position:absolute; left:20px; top:362px; width:150px; height:25px; z-index:41; background-color: #E06D68; } #Layer43 { position:absolute; left:20px; top:412px; width:150px; height:25px; z-index:42; background-color: #E06D68; } #Layer44 { position:absolute; left:20px; top:462px; width:150px; height:38px; z-index:43; background-color: #E06D68; } body { background-color: #E88F8B; } #Layer8 { position:absolute; left:155px; top:184px; width:400px; height:48px; z-index:44; } #Layer16 { position:absolute; left:670px; top:137px; width:50px; height:263px; z-index:16; background-color: #E06D68; } --> </style> <link href="estilo.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- #Layer9 { position:absolute; left:220px; top:120px; width:120px; height:40px; z-index:45; } #Layer10 { position:absolute; left:350px; top:120px; width:109px; height:35px; z-index:46; } #Layer11 { position:absolute; left:670px; top:400px; width:50px; height:100px; z-index:47; background-color: #E06D68; } #Layer12 { position:absolute; left:20px; top:500px; width:700px; height:25px; z-index:48; } --> </style> </head> <body> <div id="banner_graphic"><img src="images/banner_graphic.jpg" width="700" height="92"></div> <div class="precionormal" id="Layer8">Producto introducido</div> <div id="Layer9"><a href="index1.php">Seguir comprando</a></div> <div id="Layer10"><a href="ver_carrito.php">Ver carrito</a> </div> </body> </html>
El archivo eliminar_producto.php
Código PHP:
Ver original
<? include("lib_carrito.php"); $_SESSION["ocarrito"]->elimina_producto($_GET["linea"]); ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Avon online</title> <style type="text/css"> <!-- #banner_graphic { position:absolute; left:20px; top:20px; width:700px; height:92px; z-index:1; } #body_main_heder { position:absolute; left:20px; top:112px; width:700px; height:25px; z-index:2; } #Layer1 { position:absolute; left:20px; top:137px; width:150px; height:25px; z-index:3; } #Layer2 { position:absolute; left:20px; top:187px; width:150px; height:25px; z-index:4; } #Layer3 { position:absolute; left:20px; top:237px; width:150px; height:25px; z-index:5; } #Layer4 { position:absolute; left:20px; top:287px; width:150px; height:25px; z-index:6; } #Layer5 { position:absolute; left:20px; top:337px; width:150px; height:25px; z-index:7; } #Layer6 { position:absolute; left:20px; top:387px; width:150px; height:25px; z-index:8; } #Layer7 { position:absolute; left:20px; top:437px; width:150px; height:25px; z-index:9; } #Layer38 { position:absolute; left:20px; top:162px; width:150px; height:25px; z-index:37; background-color: #E06D68; } #Layer39 { position:absolute; left:20px; top:212px; width:150px; height:25px; z-index:38; background-color: #E06D68; } #Layer40 { position:absolute; left:20px; top:262px; width:150px; height:25px; z-index:39; background-color: #E06D68; } #Layer41 { position:absolute; left:20px; top:312px; width:150px; height:25px; z-index:40; background-color: #E06D68; } #Layer42 { position:absolute; left:20px; top:362px; width:150px; height:25px; z-index:41; background-color: #E06D68; } #Layer43 { position:absolute; left:20px; top:412px; width:150px; height:25px; z-index:42; background-color: #E06D68; } #Layer44 { position:absolute; left:20px; top:462px; width:150px; height:38px; z-index:43; background-color: #E06D68; } body { background-color: #E88F8B; } #Layer8 { position:absolute; left:155px; top:184px; width:400px; height:48px; z-index:44; } #Layer16 { position:absolute; left:670px; top:137px; width:50px; height:263px; z-index:16; background-color: #E06D68; } --> </style> <link href="estilo.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- #Layer9 { position:absolute; left:220px; top:120px; width:120px; height:40px; z-index:45; } #Layer10 { position:absolute; left:350px; top:120px; width:96px; height:36px; z-index:46; } #Layer11 { position:absolute; left:670px; top:400px; width:50px; height:100px; z-index:47; background-color: #E06D68; } #Layer12 { position:absolute; left:20px; top:500px; width:700px; height:25px; z-index:48; } --> </style> </head> <body> <div id="banner_graphic"><img src="images/banner_graphic.jpg" width="700" height="92"></div> <div class="precionormal" id="Layer8">Producto eliminado</div> <div id="Layer9"><a href="index1.php">Seguir comprando</a></div> <div id="Layer10"><a href="ver_carrito.php">Ver carrito</a> </div> </body> </html>