Returning error in insert function

1

Good morning. My function is returning an error, but I do not know what you mean, I used the Singleton pattern to do so I will post 2 codes:

<?php
    class IndicadoDAO{
        private $idIndicado;
        private $nome;
        private $email;
        private $telefone;
        private $curso;

        public function getidIndicado(){
            return $this->idIndicado;
        }
        public function getNome(){
            return $this->nome;
        }
        public function getEmail(){
            return $this->email;
        }
        public function getTelefone(){
            return $this->telefone;
        }
        public function getCurso(){
            return $this->curso;
        }
        public function setidIndicado($idIndicado){
            $this->idIndicado = $idIndicado;
        }
        public function setNome($nome){
            $this->nome = $nome;
        }
        public function setEmail($email){
            $this->email = $nome;
        }
        public function setTelefone($telefone){
            $this->telefone = $telefone;
        }
        public function setCurso($curso){
            $this->curso = $curso;
        }
    }
?>
<?php
     require_once('conexao.php');
     require_once('indicadoDAO.php');
     function inserirIndicado(indicadoDAO $indicado) {
        try{
        $sql = ("INSERT INTO indicado (nome, email, telefone, curso)
                VALUES(:nome, :email, :telefone, :curso)");

        $bau = Conexao::getConectar()->prepare($sql);
        $bau->bindValue(":nome", $indicado->getNome());
        $bau->bindValue(":email", $indicado->getEmail());
        $bau->bindValue(":telefone", $indicado->getTelefone());
        $bau->bindValue(":curso", $indicado->getCurso());
        return $bau->exec();
    } catch(PDOException $error){
            echo ("Erro encontrado") . $error->getMessage();
    }
}
?>

But when I call the function it gives error, code gives page that has the following error:

<?php
    require_once('conexao.php');
    require_once('indicado.php');
    require_once('participante.php');

     $pdo = Conexao::getConectar();
     $pdo->beginTransaction();
     inserirIndicado();
     inserirParticipante();
     $pdo->rollBack();
?>

Error result: on line 4, it says that it passes no parameter on it //
Too few arguments to function insertIndicated (), 0 passed in

Could anyone explain what's wrong on line 4?
Line 4: function insertIndicated (indicatedID $ indicated) { ... }

    
asked by anonymous 04.12.2018 / 14:18

1 answer

2

Your problem is in the inserirIndicado(); line, the insertIndicate function expects to receive an instance of indicadoDAO :

You can instantiate the class with the code $indicado = new indicadoDAO(); and then pass it the function: inserirIndicado($indicado);

<?php
    require_once('conexao.php');
    require_once('indicado.php');
    require_once('participante.php');

     $pdo = Conexao::getConectar();
     $pdo->beginTransaction();
     inserirIndicado();<------------------
     inserirParticipante();
     $pdo->rollBack();
?>
  

link

    
04.12.2018 / 15:23