Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/03/2010, 06:00
zackpaco
 
Fecha de Ingreso: marzo-2010
Mensajes: 3
Antigüedad: 14 años, 1 mes
Puntos: 0
Una ayudita plis

A ver, estoy haciendo una página con php, y el problema es con el carrito de la compra, se que la respuesta puede estar por el foro, pero os prometo que llevo 4 dias buscando y no lo encuentro.
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
  1. <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
  1. <?
  2. ?>
  3. <html>
  4. <head>
  5.     <title>Avon online</title>
  6. </head>
  7.  
  8. <body>
  9. <?
  10. if (!isset($_SESSION["ocarrito"])){
  11.     $_SESSION["ocarrito"] = new carrito();
  12. }
  13. class carrito {
  14. var $num_productos;
  15. var $array_id_prod;
  16. var $array_codigo_prod;
  17. var $array_nombre_prod;
  18. var $array_precio_prod;
  19. function carrito () {
  20.     $this->num_productos=0;
  21. }
  22. function introduce_producto($id_prod,$codigo_prod,$nombre_prod,$precio_prod){
  23.     $this->array_id_prod[$this->num_productos]=$id_prod;
  24.     $this->array_codigo_prod[$this->num_productos]=$codigo_prod;
  25.     $this->array_nombre_prod[$this->num_productos]=$nombre_prod;
  26.     $this->array_precio_prod[$this->num_productos]=$precio_prod;
  27.     $this->num_productos++;
  28. }
  29. function elimina_producto($linea){
  30.     $this->array_id_prod[$linea]=0;
  31. }
  32. function imprime_carrito(){
  33.     $suma = 0;
  34.     echo '<table border=1 cellpadding="3">
  35.    <tr>
  36.     <td><b>Codigo</b></td>
  37.    <td><b>Nombre producto</b></td>
  38.    <td><b>Precio</b></td>
  39.    <td> </td>
  40.    </tr>';
  41.     for ($i=0;$i<$this->num_productos;$i++){
  42.        if($this->array_id_prod[$i]!=0){
  43.           echo '<tr>';
  44.           echo "<td>" . $this->array_codigo_prod[$i] . "</td>";
  45.           echo "<td>" . $this->array_nombre_prod[$i] . "</td>";
  46.           echo "<td>" . $this->array_precio_prod[$i] . "</td>";
  47.           echo "<td><a href='eliminar_producto.php?linea=$i'>Eliminar producto</td>";
  48.           echo '</tr>';
  49.           $suma += $this->array_precio_prod[$i];
  50.        }
  51.     }
  52.     //muestro el total
  53.     echo "<tr><td><b>TOTAL:</b></td><td> <b>$suma</b></td><td> </td></tr>";
  54. }
  55. }
  56. ?>
  57. </body>

El archivo mete_producto.php

Código PHP:
Ver original
  1. <?
  2. include("lib_carrito.php");
  3. $_SESSION["ocarrito"]->introduce_producto($_GET["id"], $_GET["codigo"], $_GET["nombre"], $_GET["precio"]);
  4. ?>
  5. <html>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7. <title>Avon online</title>
  8. <style type="text/css">
  9. <!--
  10. #banner_graphic {
  11.     position:absolute;
  12.     left:20px;
  13.     top:20px;
  14.     width:700px;
  15.     height:92px;
  16.     z-index:1;
  17. }
  18. #body_main_heder {
  19.     position:absolute;
  20.     left:20px;
  21.     top:112px;
  22.     width:700px;
  23.     height:25px;
  24.     z-index:2;
  25. }
  26. #Layer1 {
  27.     position:absolute;
  28.     left:20px;
  29.     top:137px;
  30.     width:150px;
  31.     height:25px;
  32.     z-index:3;
  33. }
  34. #Layer2 {
  35.     position:absolute;
  36.     left:20px;
  37.     top:187px;
  38.     width:150px;
  39.     height:25px;
  40.     z-index:4;
  41. }
  42. #Layer3 {
  43.     position:absolute;
  44.     left:20px;
  45.     top:237px;
  46.     width:150px;
  47.     height:25px;
  48.     z-index:5;
  49. }
  50. #Layer4 {
  51.     position:absolute;
  52.     left:20px;
  53.     top:287px;
  54.     width:150px;
  55.     height:25px;
  56.     z-index:6;
  57. }
  58. #Layer5 {
  59.     position:absolute;
  60.     left:20px;
  61.     top:337px;
  62.     width:150px;
  63.     height:25px;
  64.     z-index:7;
  65. }
  66. #Layer6 {
  67.     position:absolute;
  68.     left:20px;
  69.     top:387px;
  70.     width:150px;
  71.     height:25px;
  72.     z-index:8;
  73. }
  74. #Layer7 {
  75.     position:absolute;
  76.     left:20px;
  77.     top:437px;
  78.     width:150px;
  79.     height:25px;
  80.     z-index:9;
  81. }
  82. #Layer38 {
  83.     position:absolute;
  84.     left:20px;
  85.     top:162px;
  86.     width:150px;
  87.     height:25px;
  88.     z-index:37;
  89.     background-color: #E06D68;
  90. }
  91. #Layer39 {
  92.     position:absolute;
  93.     left:20px;
  94.     top:212px;
  95.     width:150px;
  96.     height:25px;
  97.     z-index:38;
  98.     background-color: #E06D68;
  99. }
  100. #Layer40 {
  101.     position:absolute;
  102.     left:20px;
  103.     top:262px;
  104.     width:150px;
  105.     height:25px;
  106.     z-index:39;
  107.     background-color: #E06D68;
  108. }
  109. #Layer41 {
  110.     position:absolute;
  111.     left:20px;
  112.     top:312px;
  113.     width:150px;
  114.     height:25px;
  115.     z-index:40;
  116.     background-color: #E06D68;
  117. }
  118. #Layer42 {
  119.     position:absolute;
  120.     left:20px;
  121.     top:362px;
  122.     width:150px;
  123.     height:25px;
  124.     z-index:41;
  125.     background-color: #E06D68;
  126. }
  127. #Layer43 {
  128.     position:absolute;
  129.     left:20px;
  130.     top:412px;
  131.     width:150px;
  132.     height:25px;
  133.     z-index:42;
  134.     background-color: #E06D68;
  135. }
  136. #Layer44 {
  137.     position:absolute;
  138.     left:20px;
  139.     top:462px;
  140.     width:150px;
  141.     height:38px;
  142.     z-index:43;
  143.     background-color: #E06D68;
  144. }
  145. body {
  146.     background-color: #E88F8B;
  147. }
  148. #Layer8 {
  149.     position:absolute;
  150.     left:155px;
  151.     top:184px;
  152.     width:400px;
  153.     height:48px;
  154.     z-index:44;
  155. }
  156. #Layer16 {
  157.     position:absolute;
  158.     left:670px;
  159.     top:137px;
  160.     width:50px;
  161.     height:263px;
  162.     z-index:16;
  163.     background-color: #E06D68;
  164. }
  165.  
  166. -->
  167. </style>
  168. <link href="estilo.css" rel="stylesheet" type="text/css">
  169. <style type="text/css">
  170. <!--
  171. #Layer9 {
  172.     position:absolute;
  173.     left:220px;
  174.     top:120px;
  175.     width:120px;
  176.     height:40px;
  177.     z-index:45;
  178. }
  179. #Layer10 {
  180.     position:absolute;
  181.     left:350px;
  182.     top:120px;
  183.     width:109px;
  184.     height:35px;
  185.     z-index:46;
  186. }
  187. #Layer11 {
  188.     position:absolute;
  189.     left:670px;
  190.     top:400px;
  191.     width:50px;
  192.     height:100px;
  193.     z-index:47;
  194.     background-color: #E06D68;
  195. }
  196. #Layer12 {
  197.     position:absolute;
  198.     left:20px;
  199.     top:500px;
  200.     width:700px;
  201.     height:25px;
  202.     z-index:48;
  203. }
  204. -->
  205. </style>
  206. </head>
  207. <body>
  208. <div id="banner_graphic"><img src="images/banner_graphic.jpg" width="700" height="92"></div>
  209. <div class="precionormal" id="Layer8">Producto introducido</div>
  210. <div id="Layer9"><a href="index1.php">Seguir comprando</a></div>
  211. <div id="Layer10"><a href="ver_carrito.php">Ver carrito</a> </div>
  212.  
  213. </body>
  214. </html>

El archivo eliminar_producto.php

Código PHP:
Ver original
  1. <?
  2. include("lib_carrito.php");
  3. $_SESSION["ocarrito"]->elimina_producto($_GET["linea"]);
  4. ?>
  5. <html>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7. <title>Avon online</title>
  8. <style type="text/css">
  9. <!--
  10. #banner_graphic {
  11.     position:absolute;
  12.     left:20px;
  13.     top:20px;
  14.     width:700px;
  15.     height:92px;
  16.     z-index:1;
  17. }
  18. #body_main_heder {
  19.     position:absolute;
  20.     left:20px;
  21.     top:112px;
  22.     width:700px;
  23.     height:25px;
  24.     z-index:2;
  25. }
  26. #Layer1 {
  27.     position:absolute;
  28.     left:20px;
  29.     top:137px;
  30.     width:150px;
  31.     height:25px;
  32.     z-index:3;
  33. }
  34. #Layer2 {
  35.     position:absolute;
  36.     left:20px;
  37.     top:187px;
  38.     width:150px;
  39.     height:25px;
  40.     z-index:4;
  41. }
  42. #Layer3 {
  43.     position:absolute;
  44.     left:20px;
  45.     top:237px;
  46.     width:150px;
  47.     height:25px;
  48.     z-index:5;
  49. }
  50. #Layer4 {
  51.     position:absolute;
  52.     left:20px;
  53.     top:287px;
  54.     width:150px;
  55.     height:25px;
  56.     z-index:6;
  57. }
  58. #Layer5 {
  59.     position:absolute;
  60.     left:20px;
  61.     top:337px;
  62.     width:150px;
  63.     height:25px;
  64.     z-index:7;
  65. }
  66. #Layer6 {
  67.     position:absolute;
  68.     left:20px;
  69.     top:387px;
  70.     width:150px;
  71.     height:25px;
  72.     z-index:8;
  73. }
  74. #Layer7 {
  75.     position:absolute;
  76.     left:20px;
  77.     top:437px;
  78.     width:150px;
  79.     height:25px;
  80.     z-index:9;
  81. }
  82. #Layer38 {
  83.     position:absolute;
  84.     left:20px;
  85.     top:162px;
  86.     width:150px;
  87.     height:25px;
  88.     z-index:37;
  89.     background-color: #E06D68;
  90. }
  91. #Layer39 {
  92.     position:absolute;
  93.     left:20px;
  94.     top:212px;
  95.     width:150px;
  96.     height:25px;
  97.     z-index:38;
  98.     background-color: #E06D68;
  99. }
  100. #Layer40 {
  101.     position:absolute;
  102.     left:20px;
  103.     top:262px;
  104.     width:150px;
  105.     height:25px;
  106.     z-index:39;
  107.     background-color: #E06D68;
  108. }
  109. #Layer41 {
  110.     position:absolute;
  111.     left:20px;
  112.     top:312px;
  113.     width:150px;
  114.     height:25px;
  115.     z-index:40;
  116.     background-color: #E06D68;
  117. }
  118. #Layer42 {
  119.     position:absolute;
  120.     left:20px;
  121.     top:362px;
  122.     width:150px;
  123.     height:25px;
  124.     z-index:41;
  125.     background-color: #E06D68;
  126. }
  127. #Layer43 {
  128.     position:absolute;
  129.     left:20px;
  130.     top:412px;
  131.     width:150px;
  132.     height:25px;
  133.     z-index:42;
  134.     background-color: #E06D68;
  135. }
  136. #Layer44 {
  137.     position:absolute;
  138.     left:20px;
  139.     top:462px;
  140.     width:150px;
  141.     height:38px;
  142.     z-index:43;
  143.     background-color: #E06D68;
  144. }
  145. body {
  146.     background-color: #E88F8B;
  147. }
  148. #Layer8 {
  149.     position:absolute;
  150.     left:155px;
  151.     top:184px;
  152.     width:400px;
  153.     height:48px;
  154.     z-index:44;
  155. }
  156. #Layer16 {
  157.     position:absolute;
  158.     left:670px;
  159.     top:137px;
  160.     width:50px;
  161.     height:263px;
  162.     z-index:16;
  163.     background-color: #E06D68;
  164. }
  165.  
  166. -->
  167. </style>
  168. <link href="estilo.css" rel="stylesheet" type="text/css">
  169. <style type="text/css">
  170. <!--
  171. #Layer9 {
  172.     position:absolute;
  173.     left:220px;
  174.     top:120px;
  175.     width:120px;
  176.     height:40px;
  177.     z-index:45;
  178. }
  179. #Layer10 {
  180.     position:absolute;
  181.     left:350px;
  182.     top:120px;
  183.     width:96px;
  184.     height:36px;
  185.     z-index:46;
  186. }
  187. #Layer11 {
  188.     position:absolute;
  189.     left:670px;
  190.     top:400px;
  191.     width:50px;
  192.     height:100px;
  193.     z-index:47;
  194.     background-color: #E06D68;
  195. }
  196. #Layer12 {
  197.     position:absolute;
  198.     left:20px;
  199.     top:500px;
  200.     width:700px;
  201.     height:25px;
  202.     z-index:48;
  203. }
  204. -->
  205. </style>
  206. </head>
  207. <body>
  208. <div id="banner_graphic"><img src="images/banner_graphic.jpg" width="700" height="92"></div>
  209. <div class="precionormal" id="Layer8">Producto eliminado</div>
  210. <div id="Layer9"><a href="index1.php">Seguir comprando</a></div>
  211. <div id="Layer10"><a href="ver_carrito.php">Ver carrito</a> </div>
  212.  
  213. </body>
  214. </html>

Última edición por zackpaco; 19/03/2010 a las 08:21