FUNCTION INSERT PHP

0

I'm trying to insert into DB when and it is in the following condition:

public function cadastrar_agendamento($dados){

$consulta = $this->db->query('
    SELECT     cod_lab, cod_data, cod_horario, cod_assento, al_reg, dataagendamento
    FROM         P_chekin_Geral
    WHERE     (al_reg = "'.NULL.'") AND (cod_lab = "'.$dados['laboratorio'].'")  AND (cod_data = "'.$dados['data_prova'].'") AND (cod_data = "'.$dados['horario_prova'].'") 

'); 

if ($consuta){
        $query = mssql_query('INSERT INTO P_chekin_Geral (al_reg, dataagendamento) VALUES ("'.$dados->matricula.'"’, "'.$dados->dataagendamento.'")') ;
    }
}

But it does not insert, since the bank is already filled with NULL in the fields al_reg, datedate and the other fields are already filled in.

    
asked by anonymous 17.10.2016 / 18:49

1 answer

3

The variable consulta is not a Boolean type for you to do if($consulta) . This will never return% of%.

Make:

if($consulta->num_rows() > 0){
     // insert
}

Another thing: why do not you use the TRUE function of Active Record? It is much easier and safer.

$this->db->insert("P_chekin_Geral ", $dados);

Take a look:

link link

    
17.10.2016 / 19:08