Returning error in insert function

Asked

Viewed 38 times

1

Good morning. My function is returning an error, but I don’t know what you mean, I used the Singleton standard 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 is wrong to follow:

<?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, talks that you pass no parameter in them //
Too few Arguments to Function inserirIndicate(), 0 passed in

Could someone explain to me what’s wrong on line 4?
Row 4: Insert Function) { ... }

  • Its function inserirIndicado expects a parameter, inserirIndicado(indicadoDAO $indicado), but when you are calling her you do not inform her of your value.

  • But down in getNome() getEmail() etc, it would not pick up and save in $indicated?

1 answer

2


Your problem is on the line inserirIndicado();, the insert functionIndicated expects to receive an instance of indicadoDAO:

You can instantiate the class with the code $indicado = new indicadoDAO(); and then pass it on to 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();
?>

http://php.net/manual/en/language.oop5.basic.php

  • Thanks Edson, solved my problem!

  • Oops, that’s good. See you later

Browser other questions tagged

You are not signed in. Login or sign up in order to post.