Foros del Web » Programando para Internet » PHP »

Una ayudita plis

Estas en el tema de Una ayudita plis en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 19/03/2010, 06:00
 
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
  #2 (permalink)  
Antiguo 19/03/2010, 06:01
 
Fecha de Ingreso: marzo-2010
Mensajes: 3
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Una ayudita plis

Y el archivo ver_carrito.php
Código PHP:
Ver original
  1. <?
  2. include("lib_carrito.php");
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  8. <title>Avon online</title>
  9. <style type="text/css">
  10. <!--
  11. #banner_graphic {
  12.     position:absolute;
  13.     left:20px;
  14.     top:20px;
  15.     width:700px;
  16.     height:92px;
  17.     z-index:1;
  18. }
  19. #Layer9 {
  20.     position:absolute;
  21.     left:296px;
  22.     top:189px;
  23.     width:120px;
  24.     height:40px;
  25.     z-index:45;
  26. }
  27. #Layer13 {
  28.     position:absolute;
  29.     left:24px;
  30.     top:241px;
  31.     width:656px;
  32.     height:40px;
  33.     z-index:45;
  34. }
  35. #Layer8 {
  36.     position:absolute;
  37.     left:21px;
  38.     top:126px;
  39.     width:680px;
  40.     height:48px;
  41.     z-index:44;
  42. }
  43. body {
  44.     background-color: #E88F8B;
  45. }
  46. -->
  47. </style>
  48. <link href="estilo.css" rel="stylesheet" type="text/css">
  49. </head>
  50. <body>
  51. <div id="banner_graphic"><img src="images/banner_graphic.jpg" width="700" height="92"></div>
  52. <div id="Layer8"><?
  53. $_SESSION["ocarrito"]->imprime_carrito();
  54. ?>
  55. </div>
  56. <div id="Layer9"><a href="index.php">Seguir comprando</a></div>
  57. <div id="Layer13">
  58.     <?
  59.     if (!$HTTP_POST_VARS) {
  60.     ?>
  61.        <form method="post" action="ver_carrito.php">
  62.          <label><span class="titulo">Nombre</span>
  63.          <input type="text" name="nombre" size="25" maxlength="25">
  64.          </label>
  65.          <br>
  66.          <label><span class="titulo">Apellidos</span>
  67.          <input type="text" name="apellidos" size="40" maxlength="40">
  68.          </label>
  69.          <br>
  70.          <label><span class="titulo">Direcci&oacute;n</span>
  71.          <input type="text" name="direccion" size="80" maxlength="80">
  72.          </label>
  73.          <br>
  74.          <label><span class="titulo">C.P.</span>
  75.          <input type="text" name="codigopostal" size="5" maxlength="5">
  76.          </label>
  77.          <br>
  78.          <label><span class="titulo">Localidad</span>
  79.          <input type="text" name="localidad" size="25" maxlength="25">
  80.          </label>
  81.          <br>
  82.          <label><span class="titulo">Provincia</span>
  83.          <input type="text" name="provincia" size="80" maxlength="80">
  84.          </label>
  85.          <br>
  86.          <label><span class="titulo">Tel&eacute;fono</span>
  87.          <input type="text" name="telefono" size="80" maxlength="80">
  88.          </label>
  89.          <br>
  90.          <label><span class="titulo">Correo electr&oacute;nico</span>
  91.          <input type="text" name="email" size="80" maxlength="80">
  92.          <br>
  93.          </label>
  94.  <br>
  95.             <span class="titulo">M&eacute;todo de Pago/Precio</span>         <br>
  96.               <label>
  97.               <input type="radio" name="metododepago" value="PayPal" />
  98.               <span class="titulo">PayPal</span></label>
  99.               <span class="titulo"> / 0,00&euro;</span>
  100.               <label>
  101.                 <br>
  102.                 <input type="radio" name="metododepago" value="Transferencia" />
  103.                 <span class="titulo">Transferencia bancaria</span></label>
  104.                 <span class="titulo"> / 0,00 &euro;</span>
  105.                 <label>
  106.                 <br>
  107.                 <input type="radio" name="metododepago" value="Reembolso" />
  108.                 <span class="titulo">Contra Reembolso</span></label>
  109.                 <span class="titulo"> / 1,46 &euro;</span>
  110.               <br>
  111. <br>
  112. <span class="titulo">Los gastos de env&iacute;o se pueden consultar en <a href="http://www.correos.es/comun/tarificador/tarifas.asp">www.correos.es</a>, se enviar&aacute; por paquete azul.</span><br>
  113. <label>
  114.             <input type="submit" value="Hacer Pedido" />
  115.             <input name="redirect" type="hidden" id="redirect" value="pedidoenviado" />
  116.          </label>
  117.        </form>  
  118. <?
  119. }else{
  120.     //Estoy recibiendo el formulario, compongo el cuerpo
  121.     $cuerpo = "Formulario enviado\n";
  122.     $cuerpo = "Novedades\n";
  123.     $cuerpo .= "El método de pago elegido es: " . $HTTP_POST_VARS["metododepago"] . "\n";
  124.     $cuerpo .= "Nombre: " . $HTTP_POST_VARS["nombre"] . "\n";
  125.     $cuerpo .= "Apellidos: " . $HTTP_POST_VARS["apellidos"] . "\n";
  126.     $cuerpo .= "Dirección: " . $HTTP_POST_VARS["direccion"] . "\n";
  127.     $cuerpo .= "Código Postal: " . $HTTP_POST_VARS["codigopostal"] . "\n";
  128.     $cuerpo .= "Localidad: " . $HTTP_POST_VARS["localidad"] . "\n";
  129.     $cuerpo .= "Provincia: " . $HTTP_POST_VARS["provincia"] . "\n";
  130.     $cuerpo .= "Teléfono: " . $HTTP_POST_VARS["telefono"] . "\n";
  131.     $cuerpo .= "Correo electrónico: " . $HTTP_POST_VARS["email"] . "\n";
  132.     //mando el correo...
  133.     mail("[email protected]","Formulario recibido",$cuerpo);
  134.     //doy las gracias por el envío
  135.     echo "Pedido enviado con exito, en pocos días recibirá un correo electrónico, con los productos que haya seleccionado y su precio correspondiente, un desglose con los gastos de envío y las instrucciones para realizar el pago.
  136.  
  137. Si ha elegido como método de pago PayPal o Transferencia Bancaria, su pedido quedará retenido hasta que se reciba el pago, una vez recibido éste, se procederá al envío.
  138.  
  139. El envío de la actual campaña, se realizará aproximadamente en un plazo entre 10 y 20 días a partir de la recepción del pedido.";  
  140. }
  141. ?>
  142. </div>
  143. </body>
  144. </html>

Bien, con esto, consigo que al hacer click en el boton "Hacer pedido", me llegue a mi mail los datos introducidos en el formulario, pero no se como poner para que me llegue la funcion imprime_carrito(), vamos los productos elegidos por el cliente.

Última edición por GatorV; 19/03/2010 a las 08:22
  #3 (permalink)  
Antiguo 19/03/2010, 07:37
 
Fecha de Ingreso: marzo-2009
Ubicación: Santa Marta
Mensajes: 73
Antigüedad: 15 años
Puntos: 2
Respuesta: Una ayudita plis

pero en fin despues de su pelea....
creo que podrias decir cual es tu problema en especifico... no entendi mucho....
  #4 (permalink)  
Antiguo 19/03/2010, 08:18
 
Fecha de Ingreso: marzo-2010
Mensajes: 3
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Una ayudita plis

Hola, en el archivo ver_carrito.php, concretamente en la linea 122, es cuando empiezo a escribir el cuerpo del mail.
Se supone que debajo de la linea 132, deberia escribir algo, para que me enviara tb a mi mail, el carrito, ademas de los datos del formulario, pero no se como hacerlo
  #5 (permalink)  
Antiguo 19/03/2010, 10:30
 
Fecha de Ingreso: marzo-2010
Ubicación: Lima, Perú
Mensajes: 136
Antigüedad: 14 años, 1 mes
Puntos: 2
Respuesta: Una ayudita plis

Chochera algo practico, pasa tu css a otro archivo y luego le haces un require

Etiquetas: plis
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:11.