Jump to content
Carlos Rocha

Problema com validação

Recommended Posts

Carlos Rocha

Não sei se é devido ao cansaço, mas não estou conseguindo achar o erro,

<?php
    require_once "../_controlls/_conexao/Conexao.php";
    require_once "../_controlls/_daos/EmailsDao.php";
    
    $connection = new Conexao(); 
    $conexao = $connection->abreConexao();
    
    $email = new EmailsDao($conexao);
    
    $gravarResposta = $email->responder($_POST["idEmail"], $_POST["descricao"], $_POST["adminCli"]);

    if ($gravarResposta==1) {
        
        echo "OK";

    } else {
        
        echo "ERRO AO RESPONDER";
        
    }
 
?>

 Na validação acima, me retorna ERRO AO RESPONDER. Porém, a gravação é feita naturalmente sem erro.

 

Onde estou errando?

 

Já verifiquei, UTF sem assinatura BOM. Logo não é problema com headers.

Share this post


Link to post
Share on other sites
tiago.f

Bem, acho que a resposta é clara: a tua função "responder" não está a retornar

1

nem

"1"

 

Para mais detalhes, precisamos do código da tua classe EmailsDao

Share this post


Link to post
Share on other sites
Carlos Rocha

Segue;

 

<?php 
 
 class EmailsDao {
	 
	 private $conexao;
	 
	 public function __construct ($_conexao) {		
	     $this->conexao = $_conexao;
	 }
	 
	 public function voltarEmail ($idEmail) {

		 $string = "UPDATE emails 
		            SET respondido = 'n' , respondidoData = NULL 
				    WHERE idEmail = ".$idEmail;

        $this->conexao->query($string);
	 }
	 
	 public function responder ($idEmail, $descricao, $adminCli ) {
		 
		$string = "INSERT INTO emailsacompanhamento (idEmail, data, descricao, adminCli) 
		           VALUES (
				       ".$idEmail.",
					   NOW(),
					   '".$descricao."',
					   '".$adminCli."')
				  ";
				  
        $this->conexao->query($string);
	 }

	 public function excluir ($idEmail) {		 
	 
	     $string1 = "DELETE FROM emailsacompanhamento WHERE idEmailAcompanhamento = ".$idEmail;
	     $string2 = "DELETE FROM emails WHERE idEmail = ".$idEmail;

		 $this->conexao->query($string1);
		 $this->conexao->query($string2);
		 
	 }

	 public function cadastrar ($email) {		 
	 
	     $string = "INSERT INTO emails (
					  data, 
					  respondido, 
					  nome, 
					  email, 
					  telefone, 
					  assunto, 
					  descricao
				     ) 
				     VALUES (
					   '".$email->getData()."',
					   '".$email->getRespondido()."',
					   '".$email->getNome()."',
					   '".$email->getEmail()."',
					   '".$email->getTelefone()."',
					   '".$email->getAssunto()."',
					   '".$email->getDescricao()."')
					   ";
		 
		 $this->conexao->query($string);
		 
	 }
	 
	 public function pesquisaEmail($idEmail) {
		 $email = null;           
		 
		 $string = "SELECT 
		               idEmail, 
					   data, 
					   respondidoData, 
					   respondido, 
					   nome, 
					   email, 
					   telefone, 
					   assunto, 
					   descricao
		            FROM emails 
					WHERE idEmail = ".$idEmail;
									
		 $registros = $this->conexao->query($string);
		 $quantasLinhas = $registros->num_rows;		 
		 
		 if ($quantasLinhas > 0) {
			 
			 list ($idEmail, $data, $respondidoData, $respondido, $nome, $email, $telefone, $assunto, $descricao) = $registros->fetch_row();

			 $email = new Emails($data, $respondido, $nome, $email, $telefone, $assunto, $descricao);           			 
			 $email->setIdEmail($idEmail);
			 $email->setRespondidoData($respondidoData);
		 }

		 return $email;
		 
	 }

	 public function pesquisaEmailAcompanhamento($idEmail) {
		 $email = null;           
		 
		 $string = "SELECT 
		               idEmailAcompanhamento, 
		               idEmail, 
					   data, 
					   descricao,
					   adminCli
		            FROM emailsacompanhamento
					WHERE idEmail = ".$idEmail."
					ORDER BY idEmailAcompanhamento DESC";
									
		 $registros = $this->conexao->query($string);
		 $quantasLinhas = $registros->num_rows;		 
		 $i=0;
		 
		 if ($quantasLinhas > 0) {
			 
			 while (
			 list (
			         $idEmailAcompanhamento, 
					 $idEmail, 
					 $data, 
					 $descricao, 
					 $adminCli
				   ) = $registros->fetch_row()) {

				 $email[$i]["idEmailAcompanhamento"] = $idEmailAcompanhamento;          			 
				 $email[$i]["idEmail"] = $idEmail;           			 
				 $email[$i]["data"] = $data;           			 
				 $email[$i]["descricao"] = $descricao;           			 
				 $email[$i]["adminCli"] = $adminCli;           			 

     			 $i++;
				 
			 }
		 }

		 return $email;
		 
	 }

	 public function pesquisaEmails() {
		 $emails = null;           
		 
		 $string = "SELECT idEmail, data, respondidoData, respondido, nome, email, telefone, assunto, descricao FROM emails";
									
		 $registros = $this->conexao->query($string);
		 $quantasLinhas = $registros->num_rows;		 
		 
		 if ($quantasLinhas > 0) {
			 
			 while (list ($idEmail, $data, $respondidoData, $respondido, $nome, $email, $telefone, $assunto, $descricao) = $registros->fetch_row()) {

			 $email = new Emails($data, $respondido, $nome, $email, $telefone, $assunto, $descricao);           			 
			 $email->setIdEmail($idEmail);
			 $email->setRespondidoData($respondidoData);

			 $emails[] = $email;
			 }
		 }

		 return $emails;
		 
	 }
	 
 }
?>

 

Share this post


Link to post
Share on other sites
Carlos Rocha

Corrigi,

 

	 public function responder ($idEmail, $descricao, $adminCli ) {
		 
		$string = "INSERT INTO emailsacompanhamento (idEmail, data, descricao, adminCli) 
		           VALUES (
				       ".$idEmail.",
					   NOW(),
					   '".$descricao."',
					   '".$adminCli."')
				  ";
			
		  
        if($this->conexao->query($string)) {
	
			return 1;
	
		} else {
	
			return 0;
	
		}

	 }

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.