Codeigniter- Query in database always returning null

Asked

Viewed 98 times

0

The getlocal function which is a query in the database is always returning null even after I do an Insert in the database

denuncia_model.php file

class denuncia_model extends CI_Model {
function __construct(){
    parent::__construct();

}
public function insertlocal($local){
    $insertquery = "INSERT INTO local(estado,lng,lat) VALUES (?,?,?)";
    $this->db->query($insertquery,$local);
}
public function getlocal($local){
    $queryteste = "SELECT * FROM local WHERE estado = ? AND lng = ? AND lat = ?";
    $query = $this->db->query($queryteste,$local);
    $row = $query->row_array();
    $id = $row['id'];
    return $id;

}
public function insertdenuncia($denuncia){
    $insertdenunciaquery = "INSERT INTO denuncias(descricao,data,forma,genero,preconceito,idade,id_local) VALUES (?,?,?,?,?,?,?)";
    $this->db->query($insertdenunciaquery,$denuncia);

}

}

    $local = array($estado,$lng,$lat);
        $denuncia = array($descricao,$data,$agressao,$gender,$preconceito,$age);
        $this->denuncia_model->insertlocal($local);
        $id = $this->denuncia_model->getlocal($local);
        array_push($denuncia,$id);
        $this->denuncia_model->insertdenuncia($denuncia,$local);

inserir a descrição da imagem aqui

  • Apparently you are not returning anything in the query. Have you confirmed that your Insert is working first? If you can post a var_dump directly from the $this->db->query of each function it also helps.

  • id_local ta coming NULL, see if there are any syntax errors in it.

No answers

Browser other questions tagged

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