oikram Posted April 23, 2009 Share Posted April 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/ Share on other sites More sharing options...
radi8 Posted April 23, 2009 Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/#findComment-817678 Share on other sites More sharing options...
oikram Posted April 23, 2009 Author Share Posted April 23, 2009 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? Regards, Márcio Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/#findComment-817734 Share on other sites More sharing options...
oikram Posted April 23, 2009 Author Share Posted April 23, 2009 Solvet. I was having id_Cliente on one place and id_cliente on another place. I was a C / c :s Thanks a million for your reply, it was kick this thing off Regards, Márcio Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/#findComment-817867 Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 Solvet. Do you mean Solved? Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/#findComment-817911 Share on other sites More sharing options...
oikram Posted April 23, 2009 Author Share Posted April 23, 2009 Solved. yes. Absolutely. Quote Link to comment https://forums.phpfreaks.com/topic/155387-solved-trying-to-insert-data-on-db-im-getting-null-values-on-my-database-any-clue/#findComment-817912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.