Tema: Carrito php
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/02/2016, 19:02
rodrigoznr
 
Fecha de Ingreso: junio-2015
Mensajes: 5
Antigüedad: 8 años, 10 meses
Puntos: 0
Carrito php

Hola buenas noches... estoy trabajando en un carro de compras muy sencillo, sucede que ahora estoy con php5 cuando quiero agregar un producto al carro me da un error que no puedo darme cuenta a que se debe, les dejo el codigo a ver si me pueden ayudar.

/lib_carrito.php
Código PHP:
<?PHP

//variable de session
if (!isset($_SESSION["ocarrito"])){ 
       
$_SESSION["ocarrito"] = new carrito();
}

class 
carrito 
       
//atributos de la clase 
   
var  $num_productos
   var  
$array_id_prod
   var  
$array_nombre_prod
   var  
$array_precio_prod
}
///////// INTRODUCIR PRODUCTO FUCNCION////////////////
function introduce_producto($id_prod,$nombre_prod,$precio_prod){ 
       
$this->array_id_prod[$this->num_productos]=$id_prod
       
$this->array_nombre_prod[$this->num_productos]=$nombre_prod
       
$this->array_precio_prod[$this->num_productos]=$precio_prod
       
$this->num_productos++; 
}
////////////////////////////////////
/////////BORRAR PRODUCTO FUNCION////////////////
function elimina_producto ($linea){ 
    
$this ->array_id_prod[$linea]=0;
    }
///////////////////////////////////////////////
///////////mostrar todos los productos del carrito/////////
function imprime_carrito(){ 
       
$suma 0//guarda importe del prod
       
echo '<table border=1 cellpadding="3"> 
       <tr> 
       <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_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>"
function 
imprime_carrito(){ 
       
$suma 0
       echo 
'<table border=1 cellpadding="3"> 
       <tr> 
       <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_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>";
}
}
?>
index.php
Código PHP:
<?PHP 
include("lib_carrito.php"); 
?> 

<html> 
<head> 
       <title>Trabajando con el carrito</title> 
</head> 

<body> 


<a href="mete_producto.php?id=12&nombre=silla+modelo+jupiter&precio=80">Silla modelo jupiter 80 euros</a> 
<br> 
<br> 
<a href="mete_producto.php?id=16&nombre=mesa+camilla+oferta&precio=29">Mesa camilla en oferta 29 euros</a> 
<br> 
<br> 
<a href="mete_producto.php?id=18&nombre=Silla+oficina&precio=102">Silla oficina 102 euros</a> 
<br> 
<br> 
<a href="mete_producto.php?id=98&nombre=Aparador+cocina+blanco&precio=200">Aparador cocina blanco 200 euros</a> 
<br> 
<br> 
<br> 
- <a href="ver_carrito.php">Ver carrito</a> 
</body> 
</html>
mete_producto.php
Código PHP:
<?PHP
include("lib_carrito.php"); 
$_SESSION["ocarrito"]-> introduce_producto($_get["id"], $_get["nombre"], $_get["precio"]); 

 
?> 
<html> 
<head> 
       <title>Introduce Producto</title> 
</head> 
<body> 

Producto introducido. 
<br> 
<br> 
<a href="index.php">- Volver</a> 
<br> 
                                                                                                                     <br> 
<a href="ver_carrito.php">- Ver carrito</a> 

</body> 
</html>
el error es el siguiente:
Fatal error: Call to undefined method carrito::introduce_producto() in D:\appserver\AppServ\www\tvirtual2\mete_producto.p hp on line 3