Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/02/2015, 14:50
tuuutooo
 
Fecha de Ingreso: septiembre-2008
Mensajes: 72
Antigüedad: 15 años, 8 meses
Puntos: 0
problemas php y clases

Hola amigos, me gustaria que me pudiesen ayudar con esto Call to a member function.

Tengo un php con una clase
Código PHP:
Ver original
  1. <?PHP
  2. class Deportes{
  3.     var $bd;
  4.    
  5.     public function Deportes($bd){
  6.         $this->bd=$bd;
  7.     }
  8.    
  9.     public function getDeportesListado($estado, $reg, $limite){
  10.         $listado=array();
  11.         $sql="select id, rut, dv, nombre, apellidos, deporte, email, fono, region, comuna, to_char(fecha, 'DD-MM-YYYY'::text) as fecha from deportistas where estado=$estado order by id desc offset $reg limit $limite";
  12.         $result=$this->bd->ExecuteQuery($sql);
  13.         if($row=pg_fetch_array($result)){
  14.             do{
  15.                 array_push($listado, new detalleDeportes(
  16.                     $row['id'],
  17.                     $row['rut'],
  18.                     $row['dv'],
  19.                     $row['nombre'],
  20.                     $row['apellidos'],
  21.                     $row['deporte'],
  22.                     $row['email'],
  23.                     $row['fono'],
  24.                     $row['region'],
  25.                     $row['comuna'],
  26.                     $row['fecha']
  27.                 ));
  28.             }while($row=pg_fetch_array($result));
  29.         }
  30.         return $listado;
  31.     }
  32.    
  33.     public function ifDeportista($descripcion){
  34.         $sql="select id from musa.deportistas where rut=".$descripcion->getRut()." and lower(dv)='".strtolower($descripcion->getDv())."'";
  35.         $result=$this->bd->ExecuteQuery($sql);
  36.         if($row=pg_fetch_array($result)){
  37.             $_SESSION['deporte']=$row['id'];
  38.             return true;
  39.         }else{
  40.             return false;
  41.         }
  42.     }
  43.    
  44.     public function setDeportista($rut, $dv, $nombres, $apellidos, $deporte, $email, $fono, $region, $comuna){
  45.         $sql="insert into deportistas (rut, dv, nombres, apellidos, deporte, email, fono, region, comuna) values ($rut, '$dv', '$nombres', '$apellidos', '$deporte', $email, $fono, $region, $comuna)";
  46.         $result=$this->bd->ExecuteQuery($sql);
  47.         if(pg_affected_rows($result)==0){
  48.             return false;
  49.         }else{
  50.             $resultM=$this->bd->ExecuteQuery("select LASTVAL();");
  51.             if(!$rowM=pg_fetch_array($resultM)){
  52.                 return false;
  53.             }else{
  54.                 return true;
  55.                 $_SESSION['idm']=$rowM[0];
  56.             }
  57.         }
  58.     }
  59. }
  60.  
  61. class detalleDeportes{
  62.     var $id;
  63.     var $rut;
  64.     var $dv;
  65.     var $nombres;
  66.     var $apellidos;
  67.     var $deporte;
  68.     var $email;
  69.     var $fono;
  70.     var $region;
  71.     var $comuna;
  72.     var $fecha;
  73.    
  74.     public function detalleDeportes($id, $rut, $dv, $nombres, $apellidos, $deporte, $email, $fono, $region, $comuna, $fecha){
  75.         $this->id=$id;
  76.         $this->rut=$rut;
  77.         $this->dv=$dv;
  78.         $this->nombres=$nombres;
  79.         $this->apellidos=$apellidos;
  80.         $this->deporte=$deporte;
  81.         $this->email=$email;
  82.         $this->fono=$fono;
  83.         $this->region=$region;
  84.         $this->comuna=$comuna;
  85.         $this->fecha=$fecha;
  86.     }
  87.    
  88.     public function getId(){
  89.         return $this->id;
  90.     }
  91.    
  92.     public function getRut(){
  93.         return $this->rut;
  94.     }
  95.    
  96.     public function getDv(){
  97.         return $this->dv;
  98.     }
  99.    
  100.     public function getNombres(){
  101.         return $this->nombres;
  102.     }
  103.    
  104.     public function getApellidos(){
  105.         return $this->apellidos;
  106.     }
  107.    
  108.    
  109.     public function getDeporte(){
  110.         return $this->deporte;
  111.     }
  112.     public function getEmail(){
  113.         return $this->email;
  114.     }
  115.     public function getFono(){
  116.         return $this->fono;
  117.     }
  118.     public function getRegion(){
  119.         return $this->region;
  120.     }
  121.     public function getComuna(){
  122.         return $this->comuna;
  123.     }
  124.     public function getFecha(){
  125.         return $this->fecha;
  126.     }
  127. }
  128. ?>

y un php que recibe datos

Código PHP:
Ver original
  1. <?
  2. include("Deportes.php"); //primer php
  3. include("Validaciones.php");
  4. include("bdd.php");
  5. $bd=new BDD();
  6. $bd->Ini();
  7. $Validaciones=new Validaciones();
  8. $Deportes=new Deportes($bd);
  9. $estadosG=true;
  10. $error="";
  11.  
  12. $dv=Validaciones::cleanText($_POST['dv']);
  13. if(!$rut=Validaciones::cleanText($_POST['rut'])){
  14.     $estadosG=false;
  15.     $error="Debes ingresar el Rut.\\n";
  16. }
  17. if(!Validaciones::isRut($rut, $dv)){
  18.     $estadosG=false;
  19.     $error="Rut inválido.\\n";
  20. }
  21. if(!$nombres=Validaciones::cleanText($_POST['nombres'])){
  22.     $estadosG=false;
  23.     $error="Debes ingresar el nombre.\\n";
  24. }
  25.  
  26. if(!$apellidos=Validaciones::cleanText($_POST['apellidos'])){
  27.     $estadosG=false;
  28.     $error="Debes ingresar el Apellido.\\n";
  29. }
  30.  
  31. $email=Validaciones::cleanText($_POST['email']);
  32. Validaciones::isEmail($email);
  33.  
  34. $fono=Validaciones::cleanText($_POST['fono']);
  35. Validaciones::isNumeric($fono);
  36.  
  37. if(!$region=Validaciones::cleanText($_POST['region'])){
  38.     $estadosG=false;
  39.     $error="Debes seleccionar la Región.\\n";
  40. }
  41.  
  42. if(!$comuna=Validaciones::cleanText($_POST['comuna'])){
  43.     $estadosG=false;
  44.     $error="Debes seleccionar la Comuna.\\n";
  45. }
  46.  
  47. if(!$deporte=Validaciones::cleanText($_POST['deporte'])){
  48.     $estadosG=false;
  49.     $error="Debes seleccionar un deporte.\\n";
  50. }
  51.  
  52. if(!$fecha=Validaciones::cleanText($_POST['fecha'])){
  53.     $estadosG=false;
  54.     $error="Debes seleccionar el trato del Doctor.\\n";
  55. }
  56.  
  57. if($estadosG){
  58.     $Deportes= new detalleDeportes(0, $rut, $dv, $nombres, $apellidos, $deporte, $email, $fono, $region, $comuna, '');
  59. }
  60.  
  61. if($estadosG){
  62.     if(!$Deportes->ifDeportista($detalleDeportes)){
  63.         if(!$Deportes->setDeportista($rut, $dv, $nombres, $apellidos, $deporte, $email, $fono, $region, $comuna)){
  64.             $estadosG=false;
  65.             $error="Datos no registrados";
  66.         }
  67.     }
  68. }
  69.  
  70.  
  71. $bd->EndCommit($estadosG);
  72. if($estadosG){
  73.     header("location: listado.php");
  74. }else{
  75.     $_SESSION['error']=$error;
  76.     $_SESSION['pdata']=$_POST;
  77.     header("location: deportes_crear.php");
  78. }
  79. ?>

Mi problema viene aqui, que cuando quiero guardar el fomulario, me aparece el siguiente error Fatal error: Call to a member function getRut() on a non-object en la clase.

No se que estoy haciendo mal, si me pueden ayudar para que si existe el deportista no registre datos, pero si al consultar el rut no esta en la bdd, que me lo inserte en la base.

Muchas gracias.
Saludos