Jump to content

[SOLVED] Trying to insert data on db - I'm getting null values on my database. Any clue?


Recommended Posts

I'm getting null values on my database. Any clue?

 

     

 

    ProcessINSERT.php

 

 
      <?php
                      $id_cliente=$_POST["listaclientes"];
                      $enderecosite=$_POST["txt_endereco_site"]; 
                      $modulos=$_POST["modulos_checkbox"];

                      $listamodulos=implode($modulos, ",");
  
                    
                     //the values are sucessfully being passed on the post.

                      $site = new Site();
                      $cliente = new Cliente();
                      $site->setCliente($cliente);
                      $cliente->setId($idcliente);

                      $sitedao = new SiteDAO();
                      $sitedao->inserir($site);
  
              ?>

     

SiteDAO.class.php

 
      class SiteDAO extends DAOGeral {

      public function inserir(Site $site){

      $stmt = $this->_dbh->prepare("INSERT INTO SITE (ENDERECO_SITE, MODULOS_ACESSO_SITE, ID_CLIENTE) VALUES (?, ?, ?)");

      $stmt->bindParam(1, $site->getEndereco(), PDO::PARAM_INT );
      $stmt->bindParam(2, $site->getModulosAcesso(), PDO::PARAM_STR);
      $stmt->bindParam(3, $site->getCliente()->getId($id_cliente), PDO::PARAM_INT);            
     
      $stmt->execute();

      }
  }

       

      ?>

Site.class.php

 
      class Site {

              private $_id_site;
              private $_endereco_site;
              private $_modulos_acesso_site;

              private $_cliente;     

public function setId( $id_site ){             
      $this->_id_site = $id_site;     
}      

public function setEndereco( $endereco_site ) {        
          $this->_endereco_site = $endereco_site; 
  } 

public function setModulosAcesso( $modulos_acesso_site )        {              
        $this->_modulos_acesso_site = $modulos_acesso_site;     
}      

  public function setCliente(Cliente $cliente) {
          $this->_cliente = $cliente;
}

public function getId(){
    return $this->_id_site; 
}      

                     

public function getEndereco(){
   return $this->_endereco_site;   

                      }

                     

public function getModulosAcesso(){
                              return $this->_modulos_acesso_site;     
                      }

                     

public function getCliente(){
  return $this->_cliente; 
                      }
      }
      ?>

 

 

 

Thanks a lot,

Márcio

i dont see where you are setting the values ENDERECO_SITE, MODULOS_ACESSO_SITE, or ID_CLIENTE? Your class has the following methods:

<?php
public function setId( $id_site ){             
      $this->_id_site = $id_site;     
}     

public function setEndereco( $endereco_site ) {       
          $this->_endereco_site = $endereco_site;
  }

public function setModulosAcesso( $modulos_acesso_site )        {             
        $this->_modulos_acesso_site = $modulos_acesso_site;     
}      
?>

 

but you are not using them. Therefore the respective values are not being set.

I'm soooooo newbie. It worked!!!! Thank you thank you thank you!!!!

 

The only one that is not working now, is the id_cliente.

 

I have corrected this line:

$cliente->setId($idcliente);

 

to this:

$cliente->setId($id_cliente);

because this is the proper name of the var that guards the POST values.

 

 

I've also change this:

$stmt->bindParam(3, $site->getCliente()->getId($id_cliente), PDO::PARAM_INT);

 

to this:

$stmt->bindParam(3, $site->getCliente()->getId(), PDO::PARAM_INT);

Since I don't need any params there, right?

 

 

And I have change the order here, instead of this:

$site->setCliente($cliente);

$cliente->setId($id_cliente);

 

I'm having this:

$cliente->setId($id_cliente);

$site->setCliente($cliente);

 

I believe its more logical to first set the id of the cliente object and then pass that object as a site property. Yes?

 

 

 

Still, no luck.

 

One more little clue perhaps? :D

 

 

 

Regards,

Márcio

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.